1、创建用户和组
groupadd postgres
useradd -g postgres postgres
[root@test1 /]# groupadd postgres [root@test1 /]# useradd -g postgres postgres
2、创建postfresql的安装目录
[root@test1 tmp]# mkdir -p /postgresql/2.6 [root@test1 tmp]# chown -R postgres:postgres /postgresql
3、编译
默认安装在/usr/local/pgsql目录下,可以通过--prefix指定安装目录
./configure --prefix=/postgres/12.6
[postgres@test1 postgresql-12.6]$ ./configure --prefix=/postgres/12.6 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 block size... 8kB checking for segment size... 1GB checking for WAL block size... 8kB checking for gcc... gcc checking whether the C compiler works... yes 。。。。。。 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
注,在编译过程中,有报错,提示没有安装readline,但是readline缺失已经安装了,后来安装readline-devel后不报错。
报错信息如下:
checking for library containing readline... no configure: error: readline library not found If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support.
4、make
make all
[postgres@test1 postgresql-12.6]$ make all make -C ./src/backend generated-headers make[1]: Entering directory `/tmp/postgresql-12.6/src/backend' make -C catalog distprep generated-header-symlinks make[2]: Entering directory `/tmp/postgresql-12.6/src/backend/catalog' make[2]: Nothing to be done for `distprep'. 。。。。。。 make -C config all make[1]: Entering directory `/tmp/postgresql-12.6/config' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/tmp/postgresql-12.6/config' All of PostgreSQL successfully made. Ready to install. [postgres@test1 postgresql-12.6]$
5、make install
make install
[postgres@test1 postgresql-12.6]$ make install make -C ./src/backend generated-headers make[1]: Entering directory `/tmp/postgresql-12.6/src/backend' make -C catalog distprep generated-header-symlinks make[2]: Entering directory `/tmp/postgresql-12.6/src/backend/catalog' make[2]: Nothing to be done for `distprep'. 。。。。。。 make[1]: Entering directory `/tmp/postgresql-12.6/config' /bin/mkdir -p '/postgres/12.6/lib/pgxs/config' /bin/install -c -m 755 ./install-sh '/postgres/12.6/lib/pgxs/config/install-sh' /bin/install -c -m 755 ./missing '/postgres/12.6/lib/pgxs/config/missing' make[1]: Leaving directory `/tmp/postgresql-12.6/config' PostgreSQL installation complete. [postgres@test1 postgresql-12.6]$
6、初始化数据库
initdb -D /postgres/data
[postgres@test1 bin]$ initdb -D /postgres/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 /postgres/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 ... 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:
pg_ctl -D /postgres/data -l logfile start
[postgres@test1 bin]$
7、启动数据库
pg_ctl -D /postgres/data -l logfile start
[postgres@test1 bin]$ pg_ctl -D /postgres/data -l logfile start waiting for server to start.... done server started [postgres@test1 bin]$
安装完成。



