【CentOS7.9 源码编译安装postgres12.11】

本文介绍在CentOS7.9系统下源码编译安装Postgres12.11的详细步骤。包括上传、解压源码包,执行configure命令时遇到依赖readline、zlib包的问题及解决办法,还涵盖make、make install安装,后续数据库初始化、启动,以及用户、数据库、schema的创建。

CentOS7.9 源码编译安装postgres12.11

操作系统CPU
CentOS7.9x86_64

1、上传源码包

postgres源码下载

[root@host11-x86 ~]# cd /opt/
[root@host11-x86 opt]# ll
total 245680
-rw-r--r-- 1 root root  74554190 Sep 27 15:57 jdk-8u361-linux-aarch64.tar.gz
-rw-r--r-- 1 root root 138762230 Sep 27 15:57 jdk-8u361-linux-x64.tar.gz
-rw-r--r-- 1 root root  27583446 Sep 27 15:50 postgresql-12.11.tar.gz
drwxr-xr-x 2 root root      4096 Sep 27 23:07 tar
drwxr-xr-x 3 root root      4096 Sep 20 09:07 tpcc
-rw-r--r-- 1 root root  10658203 Sep 27 23:09 tpcc.tar.gz

2、解压源码包

[root@host11-x86 opt]# tar xf postgresql-12.11.tar.gz 
[root@host11-x86 opt]# ll
total 245684
-rw-r--r-- 1 root root  74554190 Sep 27 15:57 jdk-8u361-linux-aarch64.tar.gz
-rw-r--r-- 1 root root 138762230 Sep 27 15:57 jdk-8u361-linux-x64.tar.gz
drwxrwxrwx 6 1107 1107      4096 May 10  2022 postgresql-12.11
-rw-r--r-- 1 root root  27583446 Sep 27 15:50 postgresql-12.11.tar.gz
drwxr-xr-x 2 root root      4096 Sep 27 23:07 tar
drwxr-xr-x 3 root root      4096 Sep 20 09:07 tpcc
-rw-r--r-- 1 root root  10658203 Sep 27 23:09 tpcc.tar.gz
[root@host11-x86 opt]# cd postgresql-12.11
[root@host11-x86 postgresql-12.11]# ll
total 768
-rw-r--r--  1 1107 1107    445 May 10  2022 aclocal.m4
drwxrwxrwx  2 1107 1107   4096 May 10  2022 config
-rwxr-xr-x  1 1107 1107 581932 May 10  2022 configure
-rw-r--r--  1 1107 1107  86602 May 10  2022 configure.in
drwxrwxrwx 56 1107 1107   4096 May 10  2022 contrib
-rw-r--r--  1 1107 1107   1192 May 10  2022 COPYRIGHT
drwxrwxrwx  3 1107 1107   4096 May 10  2022 doc
-rw-r--r--  1 1107 1107   4284 May 10  2022 GNUmakefile.in
-rw-r--r--  1 1107 1107    284 May 10  2022 HISTORY
-rw-r--r--  1 1107 1107  62466 May 10  2022 INSTALL
-rw-r--r--  1 1107 1107   1665 May 10  2022 Makefile
-rw-r--r--  1 1107 1107   1212 May 10  2022 README
drwxrwxrwx 16 1107 1107   4096 May 10  2022 src
[root@host11-x86 postgresql-12.11]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         16G     0   16G   0% /dev
tmpfs            16G     0   16G   0% /dev/shm
tmpfs            16G   33M   16G   1% /run
tmpfs            16G     0   16G   0% /sys/fs/cgroup
/dev/vda1        99G  3.7G   91G   4% /
/dev/vdb        100G   57G   44G  57% /u01
tmpfs           3.2G     0  3.2G   0% /run/user/0
[root@host11-x86 postgresql-12.11]# 

3、执行 configure --prefix={安装路径}

[root@host11-x86 postgresql-12.11]# ./configure --prefix=/u01/postgresql/12
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
...................................省略N行...................................................
checking for library containing clock_gettime... none required
checking for library containing fdatasync... none required
checking for library containing sched_yield... none required
checking for library containing gethostbyname_r... none required
checking for library containing shmget... none required
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.
[root@host11-x86 postgresql-12.11]# 

4、安装报错,依赖readline 包

[root@host11-x86 postgresql-12.11]# yum install readline*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.aliyun.com
Package readline-6.2-11.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package readline-devel.x86_64 0:6.2-11.el7 will be installed
--> Processing Dependency: ncurses-devel for package: readline-devel-6.2-11.el7.x86_64
---> Package readline-static.x86_64 0:6.2-11.el7 will be installed
--> Running transaction check
---> Package ncurses-devel.x86_64 0:5.9-14.20130511.el7_4 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================
 Package                              Arch                        Version                                    Repository                 Size
=============================================================================================================================================
Installing:
 readline-devel                       x86_64                      6.2-11.el7                                 base                      139 k
 readline-static                      x86_64                      6.2-11.el7                                 base                      118 k
Installing for dependencies:
 ncurses-devel                        x86_64                      5.9-14.20130511.el7_4                      base                      712 k

Transaction Summary
=============================================================================================================================================
Install  2 Packages (+1 Dependent package)

Total download size: 969 k
Installed size: 2.9 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): readline-devel-6.2-11.el7.x86_64.rpm                                                                           | 139 kB  00:00:00     
(2/3): readline-static-6.2-11.el7.x86_64.rpm                                                                          | 118 kB  00:00:00     
(3/3): ncurses-devel-5.9-14.20130511.el7_4.x86_64.rpm                                                                 | 712 kB  00:00:00     
---------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                        1.5 MB/s | 969 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : ncurses-devel-5.9-14.20130511.el7_4.x86_64                                                                                1/3 
  Installing : readline-devel-6.2-11.el7.x86_64                                                                                          2/3 
  Installing : readline-static-6.2-11.el7.x86_64                                                                                         3/3 
  Verifying  : readline-devel-6.2-11.el7.x86_64                                                                                          1/3 
  Verifying  : readline-static-6.2-11.el7.x86_64                                                                                         2/3 
  Verifying  : ncurses-devel-5.9-14.20130511.el7_4.x86_64                                                                                3/3 

Installed:
  readline-devel.x86_64 0:6.2-11.el7                                   readline-static.x86_64 0:6.2-11.el7                                  

Dependency Installed:
  ncurses-devel.x86_64 0:5.9-14.20130511.el7_4                                                                                               

Complete!

5、再次尝试configure

[root@host11-x86 postgresql-12.11]# ./configure --prefix=/u01/postgresql/12
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
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to accept ISO C99... -std=gnu99
checking for g++... no
checking for c++... no
.................................省略N行........................................
checking for main in -lm... yes
checking for library containing setproctitle... no
checking for library containing dlsym... -ldl
checking for library containing socket... none required
checking for library containing shl_load... no
checking for library containing getopt_long... none required
checking for library containing crypt... -lcrypt
checking for library containing shm_open... -lrt
checking for library containing shm_unlink... none required
checking for library containing clock_gettime... none required
checking for library containing fdatasync... none required
checking for library containing sched_yield... none required
checking for library containing gethostbyname_r... none required
checking for library containing shmget... none required
checking for library containing readline... -lreadline
checking for inflate in -lz... no
configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.

6、安装依赖 zlib

[root@host11-x86 postgresql-12.11]# yum install zlib*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package zlib.x86_64 0:1.2.7-19.el7_9 will be updated
---> Package zlib.x86_64 0:1.2.7-21.el7_9 will be an update
---> Package zlib-devel.x86_64 0:1.2.7-21.el7_9 will be installed
---> Package zlib-static.x86_64 0:1.2.7-21.el7_9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================
 Package                            Arch                          Version                               Repository                      Size
=============================================================================================================================================
Installing:
 zlib-devel                         x86_64                        1.2.7-21.el7_9                        updates                         50 k
 zlib-static                        x86_64                        1.2.7-21.el7_9                        updates                         58 k
Updating:
 zlib                               x86_64                        1.2.7-21.el7_9                        updates                         90 k

Transaction Summary
=============================================================================================================================================
Install  2 Packages
Upgrade  1 Package

Total download size: 199 k
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/3): zlib-1.2.7-21.el7_9.x86_64.rpm                                                                                 |  90 kB  00:00:00     
(2/3): zlib-devel-1.2.7-21.el7_9.x86_64.rpm                                                                           |  50 kB  00:00:00     
(3/3): zlib-static-1.2.7-21.el7_9.x86_64.rpm                                                                          |  58 kB  00:00:00     
---------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                        583 kB/s | 199 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : zlib-1.2.7-21.el7_9.x86_64                                                                                                1/4 
  Installing : zlib-devel-1.2.7-21.el7_9.x86_64                                                                                          2/4 
  Installing : zlib-static-1.2.7-21.el7_9.x86_64                                                                                         3/4 
  Cleanup    : zlib-1.2.7-19.el7_9.x86_64                                                                                                4/4 
  Verifying  : zlib-static-1.2.7-21.el7_9.x86_64                                                                                         1/4 
  Verifying  : zlib-devel-1.2.7-21.el7_9.x86_64                                                                                          2/4 
  Verifying  : zlib-1.2.7-21.el7_9.x86_64                                                                                                3/4 
  Verifying  : zlib-1.2.7-19.el7_9.x86_64                                                                                                4/4 

Installed:
  zlib-devel.x86_64 0:1.2.7-21.el7_9                                   zlib-static.x86_64 0:1.2.7-21.el7_9                                  

Updated:
  zlib.x86_64 0:1.2.7-21.el7_9                                                                                                               

Complete!

7、再次configure

[root@host11-x86 postgresql-12.11]# 
[root@host11-x86 postgresql-12.11]# 
[root@host11-x86 postgresql-12.11]# ./configure --prefix=/u01/postgresql/12
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
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to accept ISO C99... -std=gnu99
checking for g++... no
checking for c++... no
checking whether we are using the GNU C++ compiler... no
checking whether g++ accepts -g... no
checking for gawk... gawk
.............................................................省略N行..........................................
checking thread safety of required library functions... yes
checking whether gcc -std=gnu99 supports -Wl,--as-needed... yes
configure: using compiler=gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2
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
[root@host11-x86 postgresql-12.11]# 

8、执行 make

[root@host11-x86 postgresql-12.11]# make
make -C ./src/backend generated-headers
make[1]: Entering directory `/u01/postgresql-12.11/src/backend'
make -C catalog distprep generated-header-symlinks
make[2]: Entering directory `/u01/postgresql-12.11/src/backend/catalog'
make[2]: Nothing to be done for `distprep'.
prereqdir=`cd './' >/dev/null && pwd` && \
cd '../../../src/include/catalog/' && for file in pg_proc_d.h pg_type_d.h pg_attribute_d.h pg_class_d.h pg_attrdef_d.h pg_constraint_d.h pg_inherits_d.h pg_index_d.h pg_operator_d.h pg_opfamily_d.h pg_opclass_d.h pg_am_d.h pg_amop_d.h pg_amproc_d.h pg_language_d.h pg_largeobject_metadata_d.h pg_largeobject_d.h pg_aggregate_d.h pg_statistic_ext_d.h pg_statistic_ext_data_d.h pg_statistic_d.h pg_rewrite_d.h pg_trigger_d.h pg_event_trigger_d.h pg_description_d.h pg_cast_d.h pg_enum_d.h pg_namespace_d.h pg_conversion_d.h pg_depend_d.h pg_database_d.h pg_db_role_setting_d.h pg_tablespace_d.h pg_pltemplate_d.h pg_authid_d.h pg_auth_members_d.h pg_shdepend_d.h pg_shdescription_d.h pg_ts_config_d.h pg_ts_config_map_d.h pg_ts_dict_d.h pg_ts_parser_d.h pg_ts_template_d.h pg_extension_d.h pg_foreign_data_wrapper_d.h pg_foreign_server_d.h pg_user_mapping_d.h pg_foreign_table_d.h pg_policy_d.h pg_replication_origin_d.h pg_default_acl_d.h pg_init_privs_d.h pg_seclabel_d.h pg_shseclabel_d.h pg_collation_d.h pg_partitioned_table_d.h pg_range_d.h pg_transform_d.h pg_sequence_d.h pg_publication_d.h pg_publication_rel_d.h pg_subscription_d.h pg_subscription_rel_d.h schemapg.h; do \
  rm -f $file && ln -s "$prereqdir/$file" . ; \
done
touch ../../../src/include/catalog/header-stamp
make[2]: Leaving directory `/u01/postgresql-12.11/src/backend/catalog'
make -C utils distprep generated-header-symlinks
make[2]: Entering directory `/u01/postgresql-12.11/src/backend/utils'
make[2]: Nothing to be done for `distprep'.
prereqdir=`cd './' >/dev/null && pwd` && \
cd '../../../src/include/utils/' && for file in fmgroids.h fmgrprotos.h errcodes.h; do \
  rm -f $file && ln -s "$prereqdir/$file" . ; \
done
touch ../../../src/include/utils/header-stamp
sed -f ./Gen_dummy_probes.sed probes.d >probes.h
cd '../../../src/include/utils/' && rm -f probes.h && \
    ln -s "../../../src/backend/utils/probes.h" .
make[2]: Leaving directory `/u01/postgresql-12.11/src/backend/utils'
prereqdir=`cd 'parser/' >/dev/null && pwd` && \
  cd '../../src/include/parser/' && rm -f gram.h && \
  ln -s "$prereqdir/gram.h" .
prereqdir=`cd 'storage/lmgr/' >/dev/null && pwd` && \
  cd '../../src/include/storage/' && rm -f lwlocknames.h && \
  ln -s "$prereqdir/lwlocknames.h" .
make[1]: Leaving directory `/u01/postgresql-12.11/src/backend'
make -C src all
make[1]: Entering directory `/u01/postgresql-12.11/src'
make -C common all
................................................................省略N行..........................................
make -C test/perl all
make[2]: Entering directory `/u01/postgresql-12.11/src/test/perl'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/u01/postgresql-12.11/src/test/perl'
make[1]: Leaving directory `/u01/postgresql-12.11/src'
make -C config all
make[1]: Entering directory `/u01/postgresql-12.11/config'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/u01/postgresql-12.11/config'
All of PostgreSQL successfully made. Ready to install.



9、执行 make install 安装

[root@host11-x86 postgresql-12.11]# make install
make -C ./src/backend generated-headers
make[1]: Entering directory `/u01/postgresql-12.11/src/backend'
make -C catalog distprep generated-header-symlinks
make[2]: Entering directory `/u01/postgresql-12.11/src/backend/catalog'
make[2]: Nothing to be done for `distprep'.
make[2]: Nothing to be done for `generated-header-symlinks'.
make[2]: Leaving directory `/u01/postgresql-12.11/src/backend/catalog'
make -C utils distprep generated-header-symlinks
make[2]: Entering directory `/u01/postgresql-12.11/src/backend/utils'
make[2]: Nothing to be done for `distprep'.
make[2]: Nothing to be done for `generated-header-symlinks'.
make[2]: Leaving directory `/u01/postgresql-12.11/src/backend/utils'
make[1]: Leaving directory `/u01/postgresql-12.11/src/backend'
make -C src install
make[1]: Entering directory `/u01/postgresql-12.11/src'
make -C common install
make[2]: Entering directory `/u01/postgresql-12.11/src/common'

.........................................................省略N行.......................................
make[1]: Leaving directory `/u01/postgresql-12.11/src'
make -C config install
make[1]: Entering directory `/u01/postgresql-12.11/config'
/usr/bin/mkdir -p '/u01/postgresql/12/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/u01/postgresql/12/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/u01/postgresql/12/lib/pgxs/config/missing'
make[1]: Leaving directory `/u01/postgresql-12.11/config'
PostgreSQL installation complete.

10、安装后续

[root@host11-x86 postgresql-12.11]# ll
total 1248
-rw-r--r--  1 1107 1107    445 May 10  2022 aclocal.m4
drwxrwxrwx  2 1107 1107   4096 May 10  2022 config
-rw-r--r--  1 root root 441602 Sep 28 14:36 config.log
-rwxr-xr-x  1 root root  40026 Sep 28 14:36 config.status
-rwxr-xr-x  1 1107 1107 581932 May 10  2022 configure
-rw-r--r--  1 1107 1107  86602 May 10  2022 configure.in
drwxrwxrwx 56 1107 1107   4096 May 10  2022 contrib
-rw-r--r--  1 1107 1107   1192 May 10  2022 COPYRIGHT
drwxrwxrwx  3 1107 1107   4096 May 10  2022 doc
-rw-r--r--  1 root root   4284 Sep 28 14:36 GNUmakefile
-rw-r--r--  1 1107 1107   4284 May 10  2022 GNUmakefile.in
-rw-r--r--  1 1107 1107    284 May 10  2022 HISTORY
-rw-r--r--  1 1107 1107  62466 May 10  2022 INSTALL
-rw-r--r--  1 1107 1107   1665 May 10  2022 Makefile
-rw-r--r--  1 1107 1107   1212 May 10  2022 README
drwxrwxrwx 16 1107 1107   4096 Sep 28 14:36 src
[root@host11-x86 postgresql-12.11]# useradd -m postgres -d /home/postgres -s /bin/bash
[root@host11-x86 postgresql-12.11]# mkdir -p /u01/postgresql/12/data
[root@host11-x86 postgresql-12.11]# chown -R postgres:postgres /u01/postgresql/12/data
[root@host11-x86 postgresql-12.11]# chmod -R 755 /u01/postgresql/12/data
[root@host11-x86 postgresql-12.11]# su - postgres
Last failed login: Thu Sep 28 14:33:38 CST 2023 from 159.223.45.247 on ssh:notty
There were 252 failed login attempts since the last successful login.
[postgres@host11-x86 ~]$ 
[postgres@host11-x86 ~]$ 
[postgres@host11-x86 ~]$ echo '''
> export PATH=/u01/postgresql/12/bin:$PATH
> export PGDATA=/u01/postgresql/12/data
> export PGHOME=/u01/postgresql/12
> export LANG=zh_CN.UTF-8
> export PGPORT=5432
> ''' >> ~/.bashrc
[postgres@host11-x86 ~]$ source ~/.bashrc
[postgres@host11-x86 ~]$ 
[postgres@host11-x86 ~]$ ll /u01/postgresql/12/bin/
总用量 12368
-rwxr-xr-x 1 root root   73792 928 14:39 clusterdb
-rwxr-xr-x 1 root root   73536 928 14:39 createdb
-rwxr-xr-x 1 root root   78432 928 14:39 createuser
-rwxr-xr-x 1 root root   68928 928 14:39 dropdb
-rwxr-xr-x 1 root root   68896 928 14:39 dropuser
-rwxr-xr-x 1 root root  975928 928 14:39 ecpg
-rwxr-xr-x 1 root root  142480 928 14:39 initdb
-rwxr-xr-x 1 root root   44344 928 14:39 pg_archivecleanup
-rwxr-xr-x 1 root root  130464 928 14:39 pg_basebackup
-rwxr-xr-x 1 root root  172464 928 14:39 pgbench
-rwxr-xr-x 1 root root   66984 928 14:39 pg_checksums
-rwxr-xr-x 1 root root   42880 928 14:39 pg_config
-rwxr-xr-x 1 root root   61376 928 14:39 pg_controldata
-rwxr-xr-x 1 root root   76816 928 14:39 pg_ctl
-rwxr-xr-x 1 root root  422808 928 14:39 pg_dump
-rwxr-xr-x 1 root root  109440 928 14:39 pg_dumpall
-rwxr-xr-x 1 root root   73040 928 14:39 pg_isready
-rwxr-xr-x 1 root root   93104 928 14:39 pg_receivewal
-rwxr-xr-x 1 root root   93728 928 14:39 pg_recvlogical
-rwxr-xr-x 1 root root   71328 928 14:39 pg_resetwal
-rwxr-xr-x 1 root root  187624 928 14:39 pg_restore
-rwxr-xr-x 1 root root  109784 928 14:39 pg_rewind
-rwxr-xr-x 1 root root   49168 928 14:39 pg_test_fsync
-rwxr-xr-x 1 root root   39152 928 14:39 pg_test_timing
-rwxr-xr-x 1 root root  149192 928 14:39 pg_upgrade
-rwxr-xr-x 1 root root  103904 928 14:39 pg_waldump
-rwxr-xr-x 1 root root 8251584 928 14:39 postgres
lrwxrwxrwx 1 root root       8 928 14:39 postmaster -> postgres
-rwxr-xr-x 1 root root  615456 928 14:39 psql
-rwxr-xr-x 1 root root   78016 928 14:39 reindexdb
-rwxr-xr-x 1 root root   82848 928 14:39 vacuumdb
[postgres@host11-x86 ~]$ locale -a|grep zh
zh_CN
zh_CN.gb18030
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8
zh_HK
zh_HK.big5hkscs
zh_HK.utf8
zh_SG
zh_SG.gb2312
zh_SG.gbk
zh_SG.utf8
zh_TW
zh_TW.big5
zh_TW.euctw
zh_TW.utf8

11、初始化数据库

[postgres@host11-x86 ~]$ initdb -D /u01/postgresql/12/data --locale=zh_CN.UTF8
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 "zh_CN.UTF8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

fixing permissions on existing directory /u01/postgresql/12/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 ... 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:

    pg_ctl -D /u01/postgresql/12/data -l logfile start
	
	

12、启动数据库


[postgres@host11-x86 ~]$ pg_ctl -D /u01/postgresql/12/data -l logfile start
waiting for server to start.... done
server started
[postgres@host11-x86 ~]$ 
[postgres@host11-x86 ~]$ 
[postgres@host11-x86 ~]$ ps -ef|grep postgres
root     28190 15260  0 14:40 pts/0    00:00:00 su - postgres
postgres 28191 28190  0 14:40 pts/0    00:00:00 -bash
postgres 28235     1  0 14:42 ?        00:00:00 /u01/postgresql/12/bin/postgres -D /u01/postgresql/12/data
postgres 28237 28235  0 14:42 ?        00:00:00 postgres: checkpointer   
postgres 28238 28235  0 14:42 ?        00:00:00 postgres: background writer   
postgres 28239 28235  0 14:42 ?        00:00:00 postgres: walwriter   
postgres 28240 28235  0 14:42 ?        00:00:00 postgres: autovacuum launcher   
postgres 28241 28235  0 14:42 ?        00:00:00 postgres: stats collector   
postgres 28242 28235  0 14:42 ?        00:00:00 postgres: logical replication launcher   
postgres 28243 28191  0 14:42 pts/0    00:00:00 ps -ef
postgres 28244 28191  0 14:42 pts/0    00:00:00 grep --color=auto postgres
[postgres@host11-x86 ~]$ 
[postgres@host11-x86 ~]$ netstat -nlp|grep postgres
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      28235/postgres      
tcp6       0      0 ::1:5432                :::*                    LISTEN      28235/postgres      
unix  2      [ ACC ]     STREAM     LISTENING     246302   28235/postgres       /tmp/.s.PGSQL.5432
[postgres@host11-x86 ~]$ 
[postgres@host11-x86 ~]$ 

13、创建用户、数据库、schema

[postgres@host11-x86 ~]$ psql
psql (12.11)
Type "help" for help.

postgres=#
postgres=# \d
Did not find any relations.
postgres=# \l
                                                      List of databases
   Name    |  Owner   | Encoding | Locale Provider |  Collate   |   Ctype    | ICU Locale | ICU Rules |   Access privileges
-----------+----------+----------+-----------------+------------+------------+------------+-----------+-----------------------
 postgres  | postgres | UTF8     | libc            | zh_CN.UTF8 | zh_CN.UTF8 |            |           |
 template0 | postgres | UTF8     | libc            | zh_CN.UTF8 | zh_CN.UTF8 |            |           | =c/postgres          +
           |          |          |                 |            |            |            |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | zh_CN.UTF8 | zh_CN.UTF8 |            |           | =c/postgres          +
           |          |          |                 |            |            |            |           | postgres=CTc/postgres
(3 rows)

postgres=# create user tpcc with password 'Test@1234';
CREATE ROLE
postgres=#
postgres=# create database tpcc owner tpcc;
CREATE DATABASE
postgres=#
postgres=# \l
                                                      List of databases
   Name    |  Owner   | Encoding | Locale Provider |  Collate   |   Ctype    | ICU Locale | ICU Rules |   Access privileges
-----------+----------+----------+-----------------+------------+------------+------------+-----------+-----------------------
 postgres  | postgres | UTF8     | libc            | zh_CN.UTF8 | zh_CN.UTF8 |            |           |
 template0 | postgres | UTF8     | libc            | zh_CN.UTF8 | zh_CN.UTF8 |            |           | =c/postgres          +
           |          |          |                 |            |            |            |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | zh_CN.UTF8 | zh_CN.UTF8 |            |           | =c/postgres          +
           |          |          |                 |            |            |            |           | postgres=CTc/postgres
 tpcc      | tpcc     | UTF8     | libc            | zh_CN.UTF8 | zh_CN.UTF8 |            |           |
(4 rows)

postgres=# \q
[postgres@host11-x86 ~]$ psql -Utpcc -dtpcc
psql (12.11)
Type "help" for help.

tpcc=> \dn
      List of schemas
  Name  |       Owner
--------+-------------------
 public | pg_database_owner
(1 row)

tpcc=> create schema tpcc;
CREATE SCHEMA
tpcc=> \dn
      List of schemas
  Name  |       Owner
--------+-------------------
 public | pg_database_owner
 tpcc   | tpcc
(2 rows)

tpcc=>
tpcc=> \q
[postgres@host11-x86 ~]$
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值