目录
本文是以CentOS7.9.2009版本的操作系统为基础采用编译安装的方式安装16.3版本的PostgreSQL。
安装编译安装所需环境
yum -y install gcc gcc-* make
安装PostgreSQL所需依赖
yum -y install libicu libicu-devel readline-devel zlib zlib-devel
编译安装
可以从该地址下载软件包https://ftp.postgresql.org/pub/source/v16.3/postgresql-16.3.tar.gz
# 解压源码包
tar zxvf postgresql-16.3.tar.gz
# 切换目录
cd postgresql-16.3
# --prefix指定安装目录
./configure --prefix=/usr/local/pgsql
# 编译以及安装
make && make install
配置环境
# 创建用户
adduser postgres
# 创建数据存储目录
mkdir /usr/local/pgsql/data
# 更改数据存储目录的归属用户
chown postgres /usr/local/pgsql/data
配置环境变量
cat >> /etc/profile << 'EOF'
# 配置共享库
LD_LIBRARY_PATH=/usr/local/pgsql/lib
export LD_LIBRARY_PATH
# 配置命令可搜索路径
PATH=/usr/local/pgsql/bin:$PATH
export PATH
EOF
# 刷新环境变量
source /etc/profile
登录数据库
注意:不要使用root用户登录,切换到postgres这个用户
# 切换用户
su - postgres
# 初始化数据库 -D 指定数据存储目录
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
# 启动数据库
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
# 登录数据库
/usr/local/pgsql/bin/psql
[root@bogon postgresql-16.3]# su - postgres
[postgres@bogon ~]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
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.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... America/New_York
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
initdb: hint: 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:
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
[postgres@bogon ~]$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
waiting for server to start.... done
server started
[postgres@bogon ~]$ /usr/local/pgsql/bin/psql
psql (16.3)
Type "help" for help.
postgres=#