下載安裝包:
https://www.postgresql.org/ftp/source/v12.0/
編譯依賴安裝:
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 smartmontools flex bison perl perl-devel perl-ExtUtils* OpenIPMI-tools systemtap-sdt-devel
編譯
./configure --prefix=/usr/local/postgresql-12.0 --datadir=/usr/local/postgresql-12.0/datas\ --htmldir=/usr/local/postgresql-12.0/docs --with-perl --with-openssl --enable-dtrace\ --enable-debug
創建啓動用戶
groupadd postgres useradd -g postgres postgres
創建數據庫文件存儲目錄並授權此目錄給數據庫啓動用戶
mkdir -p /usr/local/postgresql-12.0/data chown -R postgres:postgres /usr/local/postgresql-12.0
切換用戶並初始化數據庫
su postgres ./initdb -D /usr/local/postgresql-12.0/data
配置IP訪問模式
vi /usr/local/postgresql/data/pg_hba.conf # Allow replication connections from localhost, by a user with the # replication privilege. local replication all trust host replication all 127.0.0.1/32 trust host replication all ::1/128 trust host all postgres 0.0.0.0/0 trust
配置監聽地址、連接端口
vi /usr/local/postgresql/data/postgresql.conf #------------------------------------------------------------------------------ # CONNECTIONS AND AUTHENTICATION #------------------------------------------------------------------------------ # - Connection Settings - #listen_addresses = 'localhost' # what IP address(es) to listen on; listen_addresses = '*' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) #port = 5432 # (change requires restart) max_connections = 100 # (change requires restart) #superuser_reserved_connections = 3 # (change requires restart) #unix_socket_directories = '/tmp' # comma-separated list of directories # (change requires restart)
啓動數據庫
su postgres /usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data -l logfile start
登錄數據庫
/usr/local/pgsql/bin/psql
更改數據庫密碼
postgres=# \password postgres