如何安装和连接到 PostgreSQL Fedora 23

PostgreSQL 是一个免费的开源对象关系数据库管理系统 (object-RDBMS),类似于 MySQL,并且符合标准且可扩展。 它通常用作 Web 和移动应用程序的后端。 PostgreSQL,或昵称“Postgres”,与修订版一起采用 ANSI/ISO SQL 标准。

飞行前检查

  • 这些说明专门用于在 Fedora 23. 有关其他操作系统的说明,请查看如何安装和连接到 PostgreSQL Fedora 22、如何在CentOS 7上安装和连接PostgreSQL,以及如何在Ubuntu 14.04上安装和连接PostgreSQL
  • 我们将登录 Liquid Web Self Managed Fedora 23 服务器作为根。

步骤 #1:添加 PostgreSQL 9.4 存储库

在这种情况下,我们想直接从 Postgres 存储库安装 PostgreSQL 9.4.4。 首先,我们将添加 repo:

rpm -iUvh https://yum.postgresql.org/9.4/fedora/fedora-23-x86_64/pgdg-fedora94-9.4-4.noarch.rpm

步骤 #2:安装 PostgreSQL

首先,我们将通过确保可用软件包列表是最新的来观察最佳实践:

dnf -y update

然后运行一个命令进行安装:

dnf -y install postgresql94 postgresql94-server postgresql94-contrib postgresql94-libs --enablerepo=pgdg94

现在应该安装 PostgreSQL。

第 3 步:启动 PostgreSQL

将 Postgres 配置为在服务器启动时启动:
systemctl enable postgresql-9.4

这应该会产生类似于以下内容的输出:

[root@host ~]# systemctl enable postgresql-9.4
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-9.4.service to /usr/lib/systemd/system/postgresql-9.4.service.

使用以下命令初始化 Postgres:

/usr/pgsql-9.4/bin/postgresql94-setup initdb

这应该导致:

/usr/pgsql-9.4/bin/postgresql94-setup initdb
Initializing database ... OK

然后启动 Postgres:

systemctl start postgresql-9.4

第 4 步:切换到默认 PostgreSQL 用户

作为安装的一部分,Postgres 添加系统用户“postgres”并设置为使用“ident”身份验证。 Postgres 内部的角色(类似于用户)与系统用户帐户匹配。

让我们切换到该系统用户:

su - postgres

您将收到类似于以下内容的命令行:

-bash-4.3$

然后连接到 PostgreSQL 终端(以 postgres 角色):

psql

要退出 psql,请输入:

q

并返回到前一个用户,输入:
exit