官网简单安装步骤:
./configure make su make install adduser postgres mkdir /usr/local/pgsql/data chown postgres /usr/local/pgsql/data su - postgres /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 & /usr/local/pgsql/bin/createdb test /usr/local/pgsql/bin/psql test
rpm安装此处略,超级简单
https://www.postgresql.org/download/linux/redhat/
下载解压安装包
postgresql-11.4.tar.gz gunzip postgresql-11.4.tar.gz tar -xvf postgresql-11.4.tar
操作系统版本
[root@slave01~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.8 (Santiago)
./configure
[root@pg01postgresql-11.4]#cd /usr/local/postgresql-11.4 [root@pg01postgresql-11.4]#./configure ... ... 可能会报错如下
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.
根据提示,应该是没有安装 readline包。
检查是否有readline包
[root@pg01postgresql-11.4]# rpm -qa | grep readline readline-6.0-4.el6.x86_64
已经有了
通过 yum 搜索相关的readline包
[root@pg01postgresql-11.4]# yum search readline
安装 readline-devel 包
[root@slave01postgresql-11.4]#yum -y install -y readline-devel
同样还有缺少zlib-level包:
[root@slave01postgresql-11.4]#yum -y install -y zlib-devel
再次执行configure执行成功。
关于 readline 的解释,来自官网
默认情况下使用GNU Readline库。它允许psql(PostgreSQL命令行SQL解释器)记住您键入的每个命令,并允许您使用箭头键来调用和编辑以前的命令,非常适用。如果您不想使用它,则必须指定--without-readline选项进行配置。所以安装的时候,依赖包好都要安装上。
--without-readline
Prevents use of the Readline library (and libedit as well). Thisoption disables command-line
editing and history in psql, so it is notrecommended.
说明: 根据步骤2 执行 configure时报错提示,可以加上 "--without-readline" 从而避开这个ERROR,
但Postgresql官方不推荐这么做,所以还是安装吧。
[root@slave01postgresql-11.4]# make [root@slave01postgresql-11.4]# su [root@slave01postgresql-11.4]# make install [root@slave01postgresql-11.4]# adduser postgres [root@slave01postgresql-11.4]# id postgres uid=502(postgres) gid=503(postgres) groups=503(postgres) [root@slave01postgresql-11.4]# [root@slave01postgresql-11.4]# mkdir /usr/local/pgsql/data [root@slave01postgresql-11.4]# chown postgres /usr/local/pgsql/data
[postgres@slave01~]$/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 "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 /usr/local/pgsql/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default timezone ... PRC 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: /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
启动
[postgres@slave01~]$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 & [1] 75565 [postgres@slave01~]$ [postgres@slave01~]$ /usr/local/pgsql/bin/createdb test [postgres@slave01~]$ /usr/local/pgsql/bin/psql test
添加环境变量
export PGPORT=5432 export PG_HOME=/usr/local/pgsql export PATH=$PG_HOME/bin:$PATH export PGDATA=$PG_HOME/data export LD_LIBRARY_PATH=$PG_HOME/lib export LANG=en_US..utf8 环境变量PGHOST和PGPORT向客户端应用程序指定数据库服务器的主机和端口,从而覆盖已编译的默认值。 如果要远程运行客户端应用程序,那么计划使用数据库的每个用户都设置PGHOST会很方便。 可以通过命令行选项将设置传达给大多数客户端程序。
查看后台进程
[root@slave01postgresql-11.4]# ps -ef | grep postgres postgres 75565 1 0 14:18 pts/0 00:00:00 /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data postgres 75581 75565 0 14:18 ? 00:00:00 postgres: checkpointer postgres 75582 75565 0 14:18 ? 00:00:00 postgres: background writer postgres 75583 75565 0 14:18 ? 00:00:00 postgres: walwriter postgres 75584 75565 0 14:18 ? 00:00:00 postgres: autovacuum launcher postgres 75585 75565 0 14:18 ? 00:00:00 postgres: stats collector postgres 75586 75565 0 14:18 ? 00:00:00 postgres: logical replication launcher root 76403 74198 0 14:27 pts/0 00:00:00 grep postgres