postgresql-16.9 源码安装

系统:Ubuntu 24.04.2 LTS
安装

下载源码
wget https://ftp.postgresql.org/pub/source/v16.9/postgresql-16.9.tar.bz2

解压
tar xf postgresql-16.9.tar.bz2

配置
cd postgresql-16.9
./configure

➜  postgresql-16.9 ./configure

checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number... 5432
····
checking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=... no
checking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=-msse4.2... yes
checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=... no
checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc+simd... no
checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc... no
checking which CRC-32C implementation to use... SSE 4.2 with runtime check
checking for library containing sem_init... none required
checking which semaphore API to use... unnamed POSIX
checking which random number source to use... /dev/urandom
checking for /dev/urandom... yes

准备开始 Build

make
make install

新建用户,并建立存放数据到目录

adduser postgres
mkdir -p /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data

初始化数据库

切换到 postgres 用户
postgresql-16.9 su - postgres

初始化数据库
postgres@ws-aggbwy-0:~$ /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 "C.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 ... Etc/UTC
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@ws-aggbwy-0:~$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
waiting for server to start.... done
server started

手动建库

postgres@ws-aggbwy-0:~$ /usr/local/pgsql/bin/createdb ctmd
postgres@ws-aggbwy-0:~$ /usr/local/pgsql/bin/psql ctmd
psql (16.9)
Type "help" for help.

ctmd=# 
ctmd=# 

posted @ 2025-07-17 14:56  Coye  阅读(31)  评论(0)    收藏  举报