千家信息网

Linux上怎么安装PostgreSQL

发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,本篇内容主要讲解"Linux上怎么安装PostgreSQL",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Linux上怎么安装PostgreSQL"吧!环境
千家信息网最后更新 2026年10月31日Linux上怎么安装PostgreSQL

本篇内容主要讲解"Linux上怎么安装PostgreSQL",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Linux上怎么安装PostgreSQL"吧!

环境

此处是从头学PG,为了适应两年后趋势,所以我选择的都是最新的版本

  • Redhat 7.8

  • PostgreSQL 12.2 源码

下载

  1. 打开 PostgreSQL 官网 https://www.postgresql.org/,点击菜单栏上的 Download。

  2. 可以根据需要点击自己所需要的的版本,此处为了更好的学习PG,不落后其他大咖,我选择下载最新版本的源码


安装

  1. 上传并解压

      [root@node1 soft]# bzip2 -d postgresql-12.2.tar.bz2    [root@node1 soft]# tar -xvf postgresql-12.2.tar   postgresql-12.2/   postgresql-12.2/.dir-locals.el   postgresql-12.2/contrib/   postgresql-12.2/contrib/tcn/   postgresql-12.2/contrib/tcn/tcn.control   ... ...(省略输出)   [root@node1 soft]# ls -lrt    total 131200   drwxrwxrwx 6 1107 1107       273 Feb 10 17:29 postgresql-12.2   -rw-r--r-- 1 root root 134348800 Apr 30 05:29 postgresql-12.2.ta
  2. 安装 yum 包

    yum -y install readline-develyum -y install readline

    避免 ./configure 时报错

  3. configure

    [root@node1 postgresql-12.2]# ./configure checking build system type... x86_64-pc-linux-gnuchecking host system type... x86_64-pc-linux-gnuchecking which template to use... linuxchecking whether NLS is wanted... nochecking for default port number... 5432checking for block size... 8kB... ...(省略输出)checking for fop... nochecking thread safety of required library functions... yeschecking whether gcc -std=gnu99 supports -Wl,--as-needed... yesconfigure: using compiler=gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)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 -O2configure: using CPPFLAGS= -D_GNU_SOURCE configure: using LDFLAGS=  -Wl,--as-neededconfigure: creating ./config.statusconfig.status: creating GNUmakefileconfig.status: creating src/Makefile.globalconfig.status: creating src/include/pg_config.hconfig.status: creating src/include/pg_config_ext.hconfig.status: creating src/interfaces/ecpg/include/ecpg_config.hconfig.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.sconfig.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.cconfig.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.cconfig.status: linking src/include/port/linux.h to src/include/pg_config_os.hconfig.status: linking src/makefiles/Makefile.linux to src/Makefile.por
  4. make && make install

    [root@node1 postgresql-12.2]# makemake -C ./src/backend generated-headersmake[1]: Entering directory `/soft/postgresql-12.2/src/backend'make -C catalog distprep generated-header-symlinksmake[2]: Entering directory `/soft/postgresql-12.2/src/backend/catalog'... ...(省略输出)make[2]: Nothing to be done for `all'.make[2]: Leaving directory `/soft/postgresql-12.2/src/test/perl'make[1]: Leaving directory `/soft/postgresql-12.2/src'make -C config allmake[1]: Entering directory `/soft/postgresql-12.2/config'make[1]: Nothing to be done for `all'.make[1]: Leaving directory `/soft/postgresql-12.2/config'All of PostgreSQL successfully made. Ready to install.[root@node1 postgresql-12.2]# make installmake -C ./src/backend generated-headersmake[1]: Entering directory `/soft/postgresql-12.2/src/backend'make -C catalog distprep generated-header-symlinksmake[2]: Entering directory `/soft/postgresql-12.2/src/backend/catalog'make[2]: Nothing to be done for `distprep'.make[2]: Nothing to be done for `generated-header-symlinks'.... ...(省略输出)make -C config installmake[1]: Entering directory `/soft/postgresql-12.2/config'/usr/bin/mkdir -p '/usr/local/pgsql/lib/pgxs/config'/usr/bin/install -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh'/usr/bin/install -c -m 755 ./missing '/usr/local/pgsql/lib/pgxs/config/missing'make[1]: Leaving directory `/soft/postgresql-12.2/config'PostgreSQL installation complete
  5. 创建用户并配置密码

    [root@node1 postgresql-12.2]# useradd postgres[root@node1 postgresql-12.2]# passwd postgresChanging password for user postgres.New password: BAD PASSWORD: The password contains the user name in some formRetype new password: passwd: all authentication tokens updated successfully
  6. 创建数据目录并授权

    [root@node1 postgresql-12.2]# mkdir -p /data/pg_data[root@node1 postgresql-12.2]# chown postgres:postgres -R /data[root@node1 postgresql-12.2]# cd /usr/local[root@node1 local]# lltotal 0drwxr-xr-x. 2 root     root      6 Dec 14  2017 bindrwxr-xr-x. 2 root     root      6 Dec 14  2017 etcdrwxr-xr-x. 2 root     root      6 Dec 14  2017 gamesdrwxr-xr-x. 2 root     root      6 Dec 14  2017 includedrwxr-xr-x. 2 root     root      6 Dec 14  2017 libdrwxr-xr-x. 2 root     root      6 Dec 14  2017 lib64drwxr-xr-x. 2 root     root      6 Dec 14  2017 libexecdrwxr-xr-x  6 postgres postgres 56 Apr 30 05:53 pgsqldrwxr-xr-x. 2 root     root      6 Dec 14  2017 sbindrwxr-xr-x. 5 root     root     49 Apr 16 12:09 sharedrwxr-xr-x. 2 root     root      6 Dec 14  2017 src[root@node1 local]# chown postgres:postgres -R pgsq
  7. 配置 postgres 用户

    [postgres@node1 ~]$ cat .bash_profile export PATH=$PATH:/usr/local/pgsql/binexport PGDATA=/data/pg_data[postgres@node1 ~]$ source .bash_profile
  8. 初始化数据库

    [postgres@node1 ~]$ initdb -D /data/pg_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 /data/pg_data ... okcreating subdirectories ... okselecting dynamic shared memory implementation ... posixselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting default time zone ... America/New_Yorkcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing data to disk ... okinitdb: warning: enabling "trust" authentication for local connectionsYou 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/pg_data/ -l logfile star
  9. 启动数据库

    [postgres@node1 ~]$ pg_ctl -D /data/pg_data/ startwaiting for server to start....2020-04-30 06:34:29.841 EDT [53149] LOG:  starting PostgreSQL 12.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit2020-04-30 06:34:29.841 EDT [53149] LOG:  listening on IPv6 address "::1", port 54322020-04-30 06:34:29.841 EDT [53149] LOG:  listening on IPv4 address "127.0.0.1", port 54322020-04-30 06:34:29.844 EDT [53149] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"2020-04-30 06:34:29.856 EDT [53150] LOG:  database system was shut down at 2020-04-30 06:29:52 EDT2020-04-30 06:34:29.858 EDT [53149] LOG:  database system is ready to accept connections doneserver starte
  10. 关闭数据库

    [postgres@node1 ~]$ pg_ctl -D /data/pg_data/ stopwaiting for server to shut down....2020-04-30 06:35:27.573 EDT [53149] LOG:  received fast shutdown request2020-04-30 06:35:27.574 EDT [53149] LOG:  aborting any active transactions2020-04-30 06:35:27.574 EDT [53149] LOG:  background worker "logical replication launcher" (PID 53156) exited with exit code 12020-04-30 06:35:27.575 EDT [53151] LOG:  shutting down2020-04-30 06:35:27.584 EDT [53149] LOG:  database system is shut down doneserver stopped

到此,相信大家对"Linux上怎么安装PostgreSQL"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

数据 输出 数据库 版本 学习 内容 源码 用户 选择 配置 实用 更深 兴趣 实用性 实际 密码 操作简单 方法 时报 更多 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网佳科技有限公司 新华互联网科技学院 深圳科技互联网 华宇互联网科技 善班互联网科技 百单互联网科技有限公司 长亮科技 互联网金融 天扬科技互联网广告 卓越科技互联网 招聘 无锡溥仪互联网科技有限公司 互联网公司会议桌创意科技软装饰 互联网科技博主是什么意思 互联网科技教育视频 湖南诚度互联网科技有限公司 成都铂石互联网科技做什么的 互联网软件和科技 银川新华互联网科技学校联系电话 滨湖区互联网智能科技产品有哪些 宇信科技在杭州互联网排第几 工业互联网科技创业 互联网金融科技 河南云网互联网络科技有限公司 互联网科技金融公司 栖莱科技互联网股份有限公司 开一家科技互联网公司需要多少钱 中国互联网十大科技股排名 国产互联网科技公司 众联互联网络科技 互联网企业和网络科技有限公司 株洲百竞科技的互联网营销顾问
0