PostgreSQL相关总结

源码安装PostgreSQL总结

简明安装步骤(其中prefix指定PostgreSQL的安装目录,该目录与数据目录pgdata和PostgreSQL的源代码包目录均无关)

yum -y install lrzsz sysstat e4fsprogs ntp readline-devel zlib zlib-devel openssl openssl-devel pam-devel libxml2-devel libxslt-devel python-devel tcl-devel gcc make  flex bison perl perl-devel perl-ExtUtils* OpenIPMI-tools systemtap-sdt-devel

./configure --prefix=/opt/pgsql9.3.2 --with-pgport=1921 --with-perl --with-tcl --with-python --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --enable-thread-safety --with-wal-blocksize=16 --with-blocksize=16 --enable-dtrace --enable-debug(可根据自己的需要进行选择安装)

gmake world

gmake check-world -- (这个需要使用普通用户执行. 可选, 耗时较长)

gmake install-world

如果遇到依赖的动态库缺失, 需要提前安装即可.

gmake world安装包含了文档,所有的contrib.

软件安装好后, 在操作系统中创建一个普通用户, 用于初始化数据库, 开启和关闭数据库.

首先把安装好的软件链接到一个常用的目录

ln -s /opt/pgsql9.3.2 /opt/pgsql(建了一个连接/opt/pgsql;这主要是为了升级postgresql小版本方便,如当postgresql9.3.3发布时,我们可以把postgres9.3.3安装到/opt/pgsql9.3.3;然后把连接/opt/pgsql指向/opt/pgsql9.3.3就可以了)

创建用户, 并修改它的profile

useradd postgres

su - postgres

vi ~/.bash_profile

# add

export PGPORT=1921#指定端口

export PGDATA=/pgdata/pg_root#指定数据库的数据存储目录(环境变量是为了目录的切换方便)

export LANG=en_US.utf8#语言格式

export PGHOME=/opt/pgsql#安装目录(此处指定的安装目录应和prefix,ln –s 链接的目录一致)

export

LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH

export DATE=`date +"%Y%m%d%H%M"`

export PATH=$PGHOME/bin:$PATH:.

export MANPATH=$PGHOME/share/man:$MANPATH

export PGUSER=postgres

export PGHOST=$PGDATA

alias rm='rm -i'

alias ll='ls -lh'

export PGDATABASE=digoal

测试一下

su - postgres

$ psql -V

psql (PostgreSQL) 9.3.2

创建数据库集群

首先要创建数据库集群的目录

mkdir -p /pgdata/pg_root

chown -R postgres:postgres /pgdata/pg_root

初始化集群

su - postgres

initdb -D $PGDATA -E UTF8 --locale=C -U postgres –W

启动数据库前修改一下pg_hba.conf和postgresql.conf

pg_hba.conf用于配置控制访问数据库的来源

postgresql.conf是数据库的主配置文件, 最好也调整一下Linux内核参数.

启动数据库

pg_ctl start -D $PGDATA

停库

pg_ctl stop -m fast|smart|immediate -D $PGDATA

 

[postgres@gtm_standby pgbouncer]$ ll $PGDATA
total 116K
drwx------. 5 postgres postgres 4.0K Jun 12 01:08 base #默认表空间,存储数据库目录(index,toase,pg_version,table,vm,fsm,seq),临时文件目录(pgsql_tmp)
drwx------. 2 postgres postgres 4.0K Jun 12 01:18 global#pg_global存储目录,存储实例共享对象(pg_database,pg_tablespace,)
drwx------. 2 postgres postgres 4.0K Jun 12 01:08 pg_clog#存储事务日志文件,标识那些日志完成了,那些没有完成
-rw-------. 1 postgres postgres 4.4K Jun 12 01:08 pg_hba.conf#客户端认证配置文件
-rw-------. 1 postgres postgres 1.6K Jun 12 01:08 pg_ident.conf#PG用户名字映射文件
drwx------. 4 postgres postgres 4.0K Jun 12 01:08 pg_multixact#共享行锁的事务状态数据
drwx------. 2 postgres postgres 4.0K Jun 12 01:18 pg_notify#存储notify发送的数据
drwx------. 2 postgres postgres 4.0K Jun 12 01:08 pg_serial#存储串行隔离级别的事务状态数据

drwx------. 2 postgres postgres 4.0K Jun 12 01:08 pg_snapshots#保存事务状态信息快照文件
drwx------. 2 postgres postgres 4.0K Jun 12 17:26 pg_stat_tmp#统计信息的临时文件
drwx------. 2 postgres postgres 4.0K Jun 12 01:08 pg_subtrans#子事务状态数据
drwx------. 2 postgres postgres 4.0K Jun 12 01:08 pg_tblspc#表空间的软连接目录
drwx------. 2 postgres postgres 4.0K Jun 12 01:08 pg_twophase#二阶段事务状态数据
-rw-------. 1 postgres postgres 4 Jun 12 01:08 PG_VERSION
drwx------. 3 postgres postgres 4.0K Jun 12 01:08 pg_xlog#存储WAL文件
-rw-------. 1 postgres postgres 88 Jun 12 01:08 postgresql.auto.conf
-rw-------. 1 postgres postgres 21K Jun 12 01:16 postgresql.conf#数据库配置文件
-rw-------. 1 postgres postgres 59 Jun 12 01:18 postmaster.opts#记录数据库启动时的命令行选项

-rw-------. 1 postgres postgres 87 Jun 12 01:18 postmaster.pid#数据库启动的主进程信息文件(包括$PGDATA目录, 数据库启动时间, 监听端口ipc信息等)


[postgres@gtm_standby pgbouncer]$

原文地址:https://www.cnblogs.com/songyuejie/p/4570976.html