PostgreSQL 10 安装

本文详细介绍了在 Red Hat Enterprise Linux Server 7.2 系统上安装和配置 PostgreSQL 10 的步骤,包括从官网下载源码、依赖安装、编译选项设置、数据库初始化及权限配置等关键环节。

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

1. 官网下载软件

地址链接: https://www.postgresql.org/ftp/source/v10.0/
postgreSQL 的 版本是 10 操作系统是 Red Hat Enterprise Linux Server release 7.2 (Maipo)

在这里插入图片描述

[root@tjtestrac1 postgreSQL]# wget https://ftp.postgresql.org/pub/source/v10.0/postgresql-10.0.tar.gz
--2018-12-07 10:49:07--  https://ftp.postgresql.org/pub/source/v10.0/postgresql-10.0.tar.gz
Resolving ftp.postgresql.org (ftp.postgresql.org)... 72.32.157.246, 87.238.57.227, 204.145.124.244, ...
Connecting to ftp.postgresql.org (ftp.postgresql.org)|72.32.157.246|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25830653 (25M) [application/x-gzip]
Saving to: ‘postgresql-10.0.tar.gz’

100%[==================================================================================================================================>] 25,830,653  1.22MB/s   in 31s    

2018-12-07 10:49:47 (803 KB/s) - ‘postgresql-10.0.tar.gz’ saved [25830653/25830653]
 

2. 安装postgreSQL 10

解压软件包
[root@tjtestrac1 postgreSQL]# tar -xvf postgresql-10.0.tar.gz 
安装依赖的RPM包
[root@tjtestrac1 postgreSQL]# yum groupinstall "Development tools"
[root@tjtestrac1 postgreSQL]# yum install -y bison flex readline-devel zlib-devel
在源代码目录中查看编译选项
[root@tjtestrac1 postgreSQL]# cd postgresql-10.0
[root@tjtestrac1 postgresql-10.0]# ./configure --help 
Installation directories:
 --prefix=PREFIX         install architecture-independent files in PREFIX
                         [/usr/local/pgsql]
 --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                         [PREFIX]

By default, `make install' will install all the files in
`/usr/local/pgsql/bin', `/usr/local/pgsql/lib' etc.  You can specify
an installation prefix other than `/usr/local/pgsql' using `--prefix',
for instance `--prefix=$HOME'.
...
postgreSQL 编译选项众多,常用的参数如下:
参数编译选项说明
–prefix=PREFIX指定安装目录,默认的安装目录为/usr/local/pgsql
–with-pgport=PORTNUM修改默认的端口号5432,端口可以再安装之后修改
–with-blocksize=BLOCKSIZE指定数据文件的block块大小,默认是8K 适用于OLTP系统,如果是OLAP系统建议适当增加到16K,32K甚至更大
–with-segsize=SEGSIZE指定单个数据文件的大小,默认为1GB
–with-wal-blocksize指定WAL文件块的大小,默认是8KB
–with-wal-segsize指定WAL文件的大小,默认是16MB
********注意 --with-xxx-size 这几个参数 只能在编译的时候指定
创建PG的安装路径PG_HOME
[root@tjtestrac1 pg10]# mkdir -p /u02/postgreSQL/pg10
编译PG 软件到 PG_HOME
[root@tjtestrac1 postgresql-10.0]# ./configure --prefix=/u02/postgreSQL/pg10 --with-pgport=1985 --with-segsize=16 --with-wal-segsize=256
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... 1985
checking for block size... 8kB
checking for segment size... 16GB
checking for WAL block size... 8kB
checking for WAL segment size... 256MB
checking for gcc... gcc
checking whether the C compiler works... yes
...
...
config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h
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@tjtestrac1 postgresql-10.0]# gmake
......
......
gmake -C config all
gmake[1]: Entering directory `/u02/postgreSQL/postgresql-10.0/config'
gmake[1]: Nothing to be done for `all'.
gmake[1]: Leaving directory `/u02/postgreSQL/postgresql-10.0/config'
All of PostgreSQL successfully made. Ready to install.
Ready to install 提示一切正常 可以安装了
[root@tjtestrac1 postgreSQL]# gmake install
...
...
gmake[1]: Entering directory `/u02/postgreSQL/postgresql-10.0/config'
/bin/mkdir -p '/u02/postgreSQL/pg10/lib/postgresql/pgxs/config'
/bin/install -c -m 755 ./install-sh '/u02/postgreSQL/pg10/lib/postgresql/pgxs/config/install-sh'
/bin/install -c -m 755 ./missing '/u02/postgreSQL/pg10/lib/postgresql/pgxs/config/missing'
gmake[1]: Leaving directory `/u02/postgreSQL/postgresql-10.0/config'
PostgreSQL installation complete.
查看安装的PG的版本
[root@tjtestrac1 bin]# /u02/postgreSQL/pg10/bin/postgres --version
postgres (PostgreSQL) 10.0
查看PG_HOME的文件路径
[root@tjtestrac1 pg10]# tree -L 1 /u02/postgreSQL/pg10/
/u02/postgreSQL/pg10/
├── bin -- 这个文件夹里面是应用程序:分为客户端和应用端
├── include--这个文件夹是C,C++的头文件
├── lib --编译文件
└── share --PostgreSQL的文档,man, 示例文件

4 directories, 0 files

客户端程序和服务器端程序
  • 客户端
  • clusterdb,reindexdb,vacuumdb,vacuumlo,createdb,dropdb,createuser,dropuser,pg_backup,pg_dump,pg_restore
  • 服务器端
  • initdb,pg_archivecleanup,pg_controldata,pg_ctl,pg_resetwal,pg_rewind,pg_upgrade,postgres

3. 初始化数据库

在初始化数据库之前,建议在linux下创建用户postgres
[root@tjtestrac1 lib]# groupadd -g 2000 postgres
[root@tjtestrac1 lib]# useradd -g 2000 -u 2000 postgres
[root@tjtestrac1 lib]# id postgres
uid=2000(postgres) gid=2000(postgres) groups=2000(postgres)
创建新的数据库目录
pathremark
/u02/postgreSQL/db10/data数据文件路径
/u02/postgreSQL/db10/backups文件备份路径
/u02/postgreSQL/db10/scripts监控脚本路径
/u02/postgreSQL/db10/archive_walsWAL日志文件的路径
[root@tjtestrac1 postgreSQL]# mkdir -p /u02/postgreSQL/db10/{data,backups,scripts,archive_wals}
修改数据目录的权限
[root@tjtestrac1 postgreSQL]# chown -R postgres.postgres /u02/postgreSQL/db10
[root@tjtestrac1 postgreSQL]# chmod 0700 /u02/postgreSQL/db10/data/ 
创建数据库: initdb 命令创建数据库: template1 & postgres
切换用户到 postgres
[root@tjtestrac1 postgreSQL]# su - postgres
[postgres@tjtestrac1 ~]$ /u02/postgreSQL/pg10/bin/initdb --help
initdb initializes a PostgreSQL database cluster.

Usage:
  initdb [OPTION]... [DATADIR]
Options:
  -A, --auth=METHOD         default authentication method for local connections
      --auth-host=METHOD    default authentication method for local TCP/IP connections
      --auth-local=METHOD   default authentication method for local-socket connections
 [-D, --pgdata=]DATADIR     location for this database cluster
  -E, --encoding=ENCODING   set default encoding for new databases
      --locale=LOCALE       set default locale for new databases
      --lc-collate=, --lc-ctype=, --lc-messages=LOCALE
      --lc-monetary=, --lc-numeric=, --lc-time=LOCALE
                            set default locale in the respective category for
                            new databases (default taken from environment)
      --no-locale           equivalent to --locale=C
      --pwfile=FILE         read password for the new superuser from file
  -T, --text-search-config=CFG
                            default text search configuration
  -U, --username=NAME       database superuser name
  -W, --pwprompt            prompt for a password for the new superuser
  -X, --waldir=WALDIR       location for the write-ahead log directory

Less commonly used options:
  -d, --debug               generate lots of debugging output
  -k, --data-checksums      use data page checksums
  -L DIRECTORY              where to find the input files
  -n, --no-clean            do not clean up after errors
  -N, --no-sync             do not wait for changes to be written safely to disk
  -s, --show                show internal settings
  -S, --sync-only           only sync data directory

Other options:
  -V, --version             output version information, then exit
  -?, --help                show this help, then exit

help 里面列出了具体参数的详情解释,这里就不赘述了
[postgres@tjtestrac1 ~]$ /u02/postgreSQL/pg10/bin/initdb -D /u02/postgreSQL/db10/data/ -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 database encoding has accordingly been set to "UTF8".
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 /u02/postgreSQL/db10/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

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:

 /u02/postgreSQL/pg10/bin/pg_ctl -D /u02/postgreSQL/db10/data/ -l logfile start
启动数据库
[postgres@tjtestrac1 ~]$ /u02/postgreSQL/pg10/bin/pg_ctl -D /u02/postgreSQL/db10/data/ -l logfile start
waiting for server to start................. done
server started
查看数据库状态
[postgres@tjtestrac1 ~]$ /u02/postgreSQL/pg10/bin/pg_ctl -D /u02/postgreSQL/db10/data/ status
pg_ctl: server is running (PID: 27289)
/u02/postgreSQL/pg10/bin/postgres "-D" "/u02/postgreSQL/db10/data"
关闭数据库
[postgres@tjtestrac1 ~]$ /u02/postgreSQL/pg10/bin/pg_ctl -D /u02/postgreSQL/db10/data/ -ms stop
waiting for server to shut down.... done
server stopped

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值