文章目录
- 前言
- 一、PG源码安装(14.0)
- 1.创建用户
- 2.创建目录
- 3.安装yum包
- 4.编译
- 5.配置环境变量
- 6.初始化
- 7.修改参数
- 8.启动
- 9.修改数据库超级用户postgres密码
- 10.测试数据库是否已经允许连接
- 11.停止
前言
一、PG源码安装(14.0)
1.创建用户
groupadd -g 66666 postgres
useradd -u 66666 postgres -g postgres
echo "lhc" | passwd --stdin postgres
2.创建目录
mkdir -p /data/postgresql14/{pgdata,archive,scripts,backup,pg14,soft}
cp ~/softWare/postgresql-14.0.tar.gz /data/postgresql14/soft/
chown -R postgres:postgres /data/postgresql14
chmod -R 775 /data/postgresql14
3.安装yum包
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake gcc* readline-devel
4.编译
su - postgres
cd /data/postgresql14/soft
tar zxvf postgresql-14.0.tar.gz
cd postgresql-14.0
#./configure --prefix=/opt/postgres/ --with-python --with-libxml --with-libxslt
./configure --prefix=/data/postgresql14/pg14 --without-readline --with-pgport=1952
make -j 8 && make install
5.配置环境变量
cat >> ~/.bash_profile << "EOF"
export LANG=en_US.UTF-8
export PS1="[u@h W]$"
export PGPORT=1952
export PGDATA=/data/postgresql14/pgdata
export PGHOME=/data/postgresql14/pg14
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH:.
export DATE=`date +"%Y%m%d%H%M"`
export MANPATH=$PGHOME/share/man:$MANPATH
export PGHOST=$PGDATA
export PGUSER=postgres
export PGDATAbase=postgres
export PGPASSWORD=lhc
EOF
source ~/.bash_profile
6.初始化
su - postgres
/data/postgresql14/pg14/bin/initdb -D /data/postgresql14/pgdata -E UTF8 --locale=en_US.utf8 -U postgres
[postgres@oracle ~]$/data/postgresql14/pg14/bin/initdb -D /data/postgresql14/pgdata -E UTF8 --locale=en_US.utf8 -U postgres
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /data/postgresql14/pgdata ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... PRC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/data/postgresql14/pg14/bin/pg_ctl -D /data/postgresql14/pgdata -l logfile start
7.修改参数
cat >> /data/postgresql14/pgdata/postgresql.conf << "EOF"
listen_addresses = '*'
port = 1952
unix_socket_directories = '/data/postgresql14/pgdata'
logging_collector = on
log_directory = 'pg14_log'
log_filename = 'postgresql14-%Y-%m-%d_%H%M%S.log'
log_truncate_on_rotation = on
EOF
cat > /data/postgresql14/pgdata/pg_hba.conf << "EOF"
#TYPE DATAbase USER ADDRESS METHOD
local all all trust
host all all 127.0.0.1/32 trust
local replication all trust
host replication all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5
host replication all 0.0.0.0/0 md5
EOF
8.启动
su - postgres
pg_ctl start
pg_ctl status
pg_ctl stop
[postgres@oracle ~]$pg_ctl start
waiting for server to start....2021-10-22 11:00:36.079 CST [12457] LOG: redirecting log output to logging collector process
2021-10-22 11:00:36.079 CST [12457] HINT: Future log output will appear in directory "pg14_log".
stopped waiting
pg_ctl: could not start server
Examine the log output.
解决方案:
查看日志端口号重复
或者
nohup /data/postgresql14/pg14/bin/postgres -D /data/postgresql14/pgdata > /data/postgresql14/pg14/pglog.out 2>&1 &
9.修改数据库超级用户postgres密码
su - postgres
psql
possword postgres
or:
alter user postgres with password 'lhc';
psql -U postgres -h 10.206.132.17 -p 1952 -d postgres
10.测试数据库是否已经允许连接
pg_isready -p 1952
[pgsql@oracle ~]$pg_isready -p 1952
/data/postgresql14/pgdata:5432 - accepting connections
11.停止
[pgsql@oracle pgdata]$pwd
/data/postgresql14/pgdata
[pgsql@oracle pgdata]$ls -ld postmaster.pid
-rw------- 1 pgsql pgsql 100 Sep 7 09:31 postmaster.pid
[pgsql@oracle pgdata]$
kill -sigterm `head -1 /data/postgresql14/pgdata/postmaster.pid`