PostgreSQL 14.2 源码安装

文章详细描述了在Linux环境下下载PostgreSQL14.2的源码,创建用户和组,配置安装目录,安装依赖,编译安装,初始化数据目录,设置参数以及启动数据库的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载源码

(base) [root@ecs-79bd data]# wget https://ftp.postgresql.org/pub/source/v14.2/postgresql-14.2.tar.gz --no-check-certificate

(base) [root@ecs-79bd data]# tar xfz postgresql-14.2.tar.gz

创建postgres用户和组

groupadd -g 300 postgres

useradd -u 300 postgres -g postgres

创建软件目录

mkdir -p /data/db02

chown -R postgres:postgres /data/db02

创建数据目录

(base) [root@node1 ~]# mkdir -p /data/pg14_data_1922

(base) [root@node1 ~]# chown -R postgres:postgres /data/pg14_data_1922

(base) [root@node1 ~]# chown -R postgres:postgres postgresql-14.2

准备好安装必要的包

yum groupinstall "Development tools"

yum install -y bison flex readline-devel zlib-devel

运行configure程序配置编译选项

--prefix 指定安装目录

(base) [root@ecs-79bd data]# su - postgres
[postgres@ecs-79bd ~]$ cd /data/postgresql-14.2
./configure --prefix=/data/db02 --with-pgport=1922

..
configure: using CPPFLAGS= -D_GNU_SOURCE 
configure: using LDFLAGS=  -Wl,--as-needed
configure: creating ./config.status
config.status: creating GNUmakefile
config.status: creating src/Makefile.global
config.status: creating src/include/pg_config.h
config.status: creating src/include/pg_config_ext.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port

编译安装

make world

make install-world

初始化数据目录

(base) [root@node1 ~]# su - postgres

在此步骤,要求输入超级用户 postgres 用户的密码

[postgres@node1 ~]$ /data/db02/bin/initdb -D /data/pg14_data_1922 -E utf8 -W
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 text search configuration will be set to "english".

Data page checksums are disabled.

Enter new superuser password: 
Enter it again: 

fixing permissions on existing directory /data/pg14_data_1922 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
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/db02/bin/pg_ctl -D /data/pg14_data_1922 -l logfile start

编辑参数文件

[postgres@node1 ~]$ vim /data/pg14_data_1922/postgresql.conf
listen_addresses = '*'          # what IP address(es) to listen on;

port = 1922                             # (change requires restart)
max_connections = 100                   # (change requires restart)

logging_collector = on          # Enable capturing of stderr and csvlog

log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,

log_rotation_age = 1d                   # Automatic rotation of logfiles will
                                        # happen after that time.  0 disables.
log_rotation_size = 100MB               # Automatic rotation of logfiles will
                                        # happen after that much log output.
                                        # 0 disables.
log_truncate_on_rotation = off          # If on, an existing log file with the

# - Memory -

shared_buffers = 128MB                  # min 128kB
                                        # (change requires restart)

work_mem = 4MB                          # min 64kB

启动数据库

/data/db02/bin/pg_ctl -D /data/pg14_data_1922 start

查看数据库运行状态

/data/db02/bin/pg_ctl -D /data/pg14_data_1922 status

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值