单机安装虽然简单,但确实做高可用前最基础的步骤,仍然是需要掌握的,PostgreSQL的安装有rpm包,也有源码编译,rpm安装路径指定起来较麻烦,源码编译则更灵活,且一次编译后,可以复制到其他机器上继续使用。
1. 必备条件
1.1 环境说明
| 环境准备 | 说明 |
|---|---|
| 操作系统 | Centos 7.8 x86_64 |
| PG版本 | postgresql-13.5.tar.gz |
| 安装目录 | /data/pgsql13.5 |
| 数据目录 | /data/pgdata |
1.2 创建用户
useradd -u 5432 postgres
2. 编译安装
2.1 必要包安装
提前安装perl-devel,python-devel,readline
yum install perl-ExtUtils-Embed -y yum install readline readline-devel -y yum install perl-devel -y yum install python-devel -y
2.2 编译安装
root用户操作
./configure --prefix=/data/pgsql13.5 --with-perl --with-python make && make install ln -sf /data/pgsql13.5 /usr/local/pgsql
执行结果1: configure
[root@dbtest postgresql-13.5]# ./configure --prefix=/data/pgsql13.5 --with-perl --with-python 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 ~~中间省略~~ t-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
执行结果2:make install
[root@dbtest postgresql-13.5]# make && make install make -C ./src/backend generated-headers make[1]: Entering directory `/data/postgresql-13.5/src/backend' make -C catalog distprep generated-header-symlinks make[2]: Entering directory `/data/postgresql-13.5/src/backend/catalog' make[2]: Nothing to be done for `distprep'. prereqdir=`cd './' >/dev/null && pwd` && \ ~~中间省略~~ make[2]: Leaving directory `/data/postgresql-13.5/src/test/perl' /usr/bin/mkdir -p '/data/pgsql13.5/lib/pgxs/src' /usr/bin/install -c -m 644 Makefile.global '/data/pgsql13.5/lib/pgxs/src/Makefile.global' /usr/bin/install -c -m 644 Makefile.port '/data/pgsql13.5/lib/pgxs/src/Makefile.port' /usr/bin/install -c -m 644 ./Makefile.shlib '/data/pgsql13.5/lib/pgxs/src/Makefile.shlib' /usr/bin/install -c -m 644 ./nls-global.mk '/data/pgsql13.5/lib/pgxs/src/nls-global.mk' make[1]: Leaving directory `/data/postgresql-13.5/src' make -C config install make[1]: Entering directory `/data/postgresql-13.5/config' /usr/bin/mkdir -p '/data/pgsql13.5/lib/pgxs/config' /usr/bin/install -c -m 755 ./install-sh '/data/pgsql13.5/lib/pgxs/config/install-sh' /usr/bin/install -c -m 755 ./missing '/data/pgsql13.5/lib/pgxs/config/missing' make[1]: Leaving directory `/data/postgresql-13.5/config'
2.3 环境变量设置
root用户操作
echo "export PATH=\$PATH:/usr/local/pgsql/bin" >> /etc/profile echo "export LD_LIBRARY_PATH=/usr/local/pgsql/lib:\$LD_LIBRARY_PATH" >> /etc/profile echo "export PGDATA=/data/pgdata" >> /etc/profile
修改软件属组
chown postgres:postgres pgsql13.5/ chown -R postgres:postgres pgsql13.5/
2.4 初始化数据库
初始化数据库并不等于创建数据库,可以理解为生成实例
postgres用户操作
su - postgres initdb
执行结果
[postgres@dbtest ~]$ initdb 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. creating directory /data/pgdata ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... America/New_York 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 /data/pgdata -l logfile start
2.5 启动数据库
更精确的是启动实例
postgres用户操作
pg_ctl -D /data/pgdata -l logfile start
2.6 登录验证
[postgres@dbtest ~]$ psql psql (13.5) Type "help" for help. postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (3 rows)
文章转载自DigOps,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




