[ad_1]
在本教程中,我们将向您展示如何在您的 Debian 9 上安装 PostgreSQL。对于那些不知道的人,PostgreSQL 是一个免费的开源对象关系数据库管理系统 (object-RDBMS),类似于 MySQL ,并且符合标准且可扩展。 它通常用作 Web 和移动应用程序的后端。 PostgreSQL,或绰号为“Postgres”,与修订版一起采用 ANSI/ISO SQL 标准。
本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo
‘ 到命令以获取 root 权限。 我将向您展示在 Debian 9 (Stretch) 服务器上逐步安装 PostgreSQL。
在 Debian 9 Stretch 上安装 PostgreSQL
第 1 步。在我们安装任何软件之前,重要的是通过运行以下命令确保您的系统是最新的 apt-get
终端中的命令:
apt-get update apt-get upgrade
步骤 2. 安装 PostgreSQL 服务器。
PostgreSQL 在默认存储库中可用。 现在,使用 apt-get 安装 PostgreSQL 包:
apt-get install postgresql-9.6
还需要使用以下命令启用 PostgreSQL 服务以在重新启动时启动:
systemctl start postgresql systemctl enable postgresql
现在我们可以使用一些命令来确认安装。 它们如下所示:
ps -ef | grep postgre
您应该在终端上看到类似这样的内容:
postgres 32162 1 0 22:58 ? 00:00:00 /usr/lib/postgresql/9.4/bin/postgres -D /var/lib/ postgresql/9.4/main -c config_file=/etc/postgresql/9.4/main/postgresql.conf postgres 32168 32164 0 22:58 ? 00:00:00 postgres: checkpointer process postgres 32167 32164 0 22:58 ? 00:00:00 postgres: writer process postgres 32169 32164 0 22:58 ? 00:00:00 postgres: wal writer process postgres 32160 32164 0 22:58 ? 00:00:00 postgres: autovacuum launcher process postgres 32171 32164 0 22:58 ? 00:00:00 postgres: stats collector process
步骤 3. 访问 PostgreSQL 命令提示符。
安装 PostgreSQL 数据库服务器后,默认情况下,它会创建一个角色为“postgres”的用户“postgres”。 它还创建一个具有相同名称“postgres”的系统帐户。 因此,要连接到 postgres 服务器,请以用户 postgres 登录到您的系统并连接数据库:
su - postgres psql
现在您已登录到 PostgreSQL 数据库服务器。 要检查登录信息,请从数据库命令提示符使用以下命令:
postgres-# conninfo
要断开与 PostgreSQL 数据库命令提示符的连接,只需键入以下命令并按 Enter。 它会让你回到 Ubuntu 命令提示符:
postgres-# q
创建一个新的用户和数据库:
### For example, let us create a new user called “idroot” with password “idrootus”, and database called “idrootdb”. ### sudo -u postgres createuser -D -A -P idroot sudo -u postgres createdb -O idroot idrootdb
恭喜! 您已成功安装 PostgreSQL 服务器。 感谢您使用本教程在 Debian 9 Stretch 系统中安装 PostgreSQL。 如需更多帮助或有用信息,我们建议您查看 PostgreSQL 官方网站.
[ad_2]