pgpoolII的管理功能

pgpool是postgresql的中间件,他的主要功能包括:

  • Connection Pooling 连接池
  • Replication 双写
  • Load Balance 负载均衡
  • Limiting Exceeding Connections 连接限制
  • Parallel Query 并行查询

除此以外,pgpool还提供了对数据库节点的健康检查功能,自动fail over。

对pgpool的管理,pgpool本身除了工作端口(默认5433)以外,还开放一个pcp端口9898,类似FTP的控制端口。通过pcp端口可以获取pgpool的运行时信息,也可以进行运行时的操作。这些功能罗列在:

http://pgpool.projects.postgresql.org/pgpool-II/doc/pgpool-en.html#reference

封装这些命令的二进制文件也随着pgpool发行,由于是通过网络通信,所以并不要求这些工具与pgpool安装在同一台机器上。

除此以外,为了用户友好,pgpool还有一个具有UI的用户管理工具。这个工具的功能包括:

  • 系统信息,主要是pcp的信息
  • 配置文件编辑,这个功能似乎要求pgpooladmin和pgpool安装在一台机器上以便直接都写配置文件
  • 切分规则编辑

另外,pgpool还通过一些自定义的SQL语句允许用户从工作端口提取一些配置信息和运行时信息:

http://pgpool.projects.postgresql.org/pgpool-II/doc/pgpool-en.html#show-commands

DB dump with chroot

I caught chroot first time when attempting to install gentoo linux. Of course, its a tool of great useful. Two months ago I had my laptop crashed, and all static files were recovery easily by copy while raw db data file seems to be difficult to handle.

The old file system is in a mobile disk, mounted at /media/disk-1/. Now I try to use chroot to rollback to that environment, so that all standard dump tools will be available.

Before you chroot to the system, don’t forget to bind /dev to new location. Or you might get error prompt such as “/dev/null Permission Denied” (it’s a common error). Just execute command below:
$ sudo mount –bind /dev /media/disk-1/dev

Then change root to my old system:
$ sudo chroot /media/disk-1

Now you become root user automatically.

MySQL Dump

In a standard ubuntu mysql installation, we should launch mysql db from init.d by:
# /etc/init.d/mysql start

But it’s no longer available in such environment. Fortunately, there is a direct way:
# mysqld_safe &

OK, go on to dump database with mysqldump:
# mysqldump –all-databases > mysql_dump_file

Postgresql Dump

We cannot use init.d to start pgsql either. Therefore, try to run it by:
# su postgres -c “/usr/lib/postgresql/8.3/bin/pg_ctl start -D /etc/postgresql/8.3/main”

/etc/postgresql/8.3/main is the default data directory in standard installation(with apt-get). This directory is supposed to contain a file named with “postgesql.conf”

Now pgsql db is also running. As root user we have no privilege to run pgsql utilities. so take following steps:
# touch pgsql_dump_file
# chmod a+w pgsql_dump_file
# su postgres -c “pg_dumpall -f pgsql_dump_file”

Conclusion

Personally, I found it’s too complex and low efficiency to backup and restore data with mysql and postgresql. If there is no critical requirement(just like personal data management), file based db(Surely I mean sqlite) is no doubt better choice. Easy management(lots of gui tool now provided), smooth copy and move, standard db interface for programming, and enough functionality.

[旧]Up and Running: PostgreSQL and PostGIS on Ubuntu 8.10, Step By Step

每次安装pgsql的过程都是这么震撼人心。以下在Ubuntu 8.10上安装配置运行pgsql及postgis的简单步骤。和Windows相比,用apt-get安装不会再有服务安装不上的问题,但是可能会有包装不全、缺少配置的问题。

首先用apt-get下载安装pgsql和postgis的需要的包

sudo apt-get install postgresql-8.3 postgresql-8.3-postgis postgresql-client-8.3 postgresql-contrib-8.3 pgadmin3

安装过程中会提示创建一个默认名为postgres的用户。

安装结束后,启动pgsql服务器

sudo /etc/init.d/postgresql-8.3 start

在默认情况下pgsql ident的设置为postgres用户用ident sameuser的方式登录,这种方式类似于sqlserver使用windows的用户管理。因此要用postgres用户登录系统。

修改postgres用户的密码

sudo passwd postgres

用新密码登录为postgres

su – postgres

运行psql,可以检查pgsql的运行情况

psql

可以在psql中给postgres用户设置数据库密码

ALTER USER postgres ENCRYPTED PASSWORD ‘yournewpassword’;

继续在psql中创建plsql语言。如果安装时遗漏了contrib包这一步是不能完成的。

CREATE LANGUAGE plsql;

退出psql,创建Postgis数据库。

createdb postgis

导入postgis的两个sql文件,其中定义了EPSG数据库和Geometry类型。

psql -d postgis -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql
psql -d postgis -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql

进入psql对当前用户GRAND ALL

GRANT ALL ON TABLE geometry_columns TO postgres;
GRANT ALL ON TABLE spatial_ref_sys TO postgres;

这样做的结果是这两张表被导入到默认的postgres数据库中。这样今后创建postgis数据库就可以以postgres为template_db,不过这么做的后果是这两张表的owner都是postgres。在GeoServer里创建FeatureType时必须用postgres用户登录,否则权限不足。

这时PostGIS应该可以正常工作了,可以尝试导入shp

shp2pgsql /your/shp/file tablename | psql newgisdb

创建一个新的数据库用户

createuser -p username

修改/etc/postgresql/8.3/main/pg_hda.conf,设置数据库访问的认证方式

将local all all一行的验证方式(method)由ident sameuser改为password就可以用密码登录psql了,在python-psycopg中用新建的用户连接pgsql也不会报ident失败了。

将host all 127.0.0.1/32一行的验证方式也改为password就可以在本地用jdbc以用户名密码连接数据库了。