如何在Ubuntu 20.04上安装和使用PostgreSQL

介绍 (Introduction)

Relational database management systems are a key component of many web sites and applications. They provide a structured way to store, organize, and access information.

关系数据库管理系统是许多网站和应用程序的关键组件。 它们提供了一种结构化的方式来存储,组织和访问信息。

PostgreSQL, or Postgres, is a relational database management system that provides an implementation of the SQL querying language. It’s standards-compliant and has many advanced features like reliable transactions and concurrency without read locks.

PostgreSQL或Postgres是一种关系数据库管理系统,提供SQL查询语言的实现。 它符合标准,并具有许多高级功能,例如可靠的事务处理和并发,没有读锁。

This guide demonstrates how to install Postgres on an Ubuntu 20.04 server. It also provides some instructions for general database administration.

本指南演示了如何在Ubuntu 20.04服务器上安装Postgres。 它还提供了一些有关常规数据库管理的说明。

先决条件 (Prerequisites)

To follow along with this tutorial, you will need one Ubuntu 20.04 server that has been configured by following our Initial Server Setup for Ubuntu 20.04 guide. After completing this prerequisite tutorial, your server should have a non-root user with sudo permissions and a basic firewall.

要继续本教程,您将需要按照我们的《 Ubuntu 20.04初始服务器设置》指南配置一台Ubuntu 20.04服务器。 完成此先决条件教程之后,您的服务器应具有具有sudo权限的非root用户和基本防火墙。

第1步-安装PostgreSQL (Step 1 — Installing PostgreSQL)

Ubuntu’s default repositories contain Postgres packages, so you can install these using the apt packaging system.

Ubuntu的默认存储库包含Postgres软件包,因此您可以使用apt打包系统安装它们。

If you’ve not done so recently, refresh your server’s local package index:

如果您最近没有这样做,请刷新服务器的本地软件包索引:

  • sudo apt update

    sudo apt更新

Then, install the Postgres package along with a -contrib package that adds some additional utilities and functionality:

然后,安装Postgres软件包以及-contrib软件包,该软件包添加了一些其他实用程序和功能:

  • sudo apt install postgresql postgresql-contrib

    sudo apt安装postgresql postgresql-contrib

Now that the software is installed, we can go over how it works and how it may be different from other relational database management systems you may have used.

现在已经安装了该软件,接下来我们将介绍它的工作原理以及它与您可能使用的其他关系数据库管理系统的不同之处。

第2步-使用PostgreSQL角色和数据库 (Step 2 — Using PostgreSQL Roles and Databases)

By default, Postgres uses a concept called “roles” to handle authentication and authorization. These are, in some ways, similar to regular Unix-style accounts, but Postgres does not distinguish between users and groups and instead prefers the more flexible term “role”.

默认情况下,Postgres使用称为“角色”的概念来处理身份验证和授权。 从某种意义上讲,它们类似于常规的Unix风格的帐户,但是Postgres不区分用户和组,而是喜欢使用更灵活的术语“角色”。

Upon installation, Postgres is set up to use ident authentication, meaning that it associates Postgres roles with a matching Unix/Linux system account. If a role exists within Postgres, a Unix/Linux username with the same name is able to sign in as that role.

安装后,Postgres设置为使用身份认证,这意味着它将Postgres角色与匹配的Unix / Linux系统帐户相关联。 如果Postgres中存在角色,则具有相同名称的Unix / Linux用户名可以作为该角色登录。

The installation procedure created a user account called postgres that is associated with the default Postgres role. In order to use Postgres, you can log into that account.

安装过程创建了一个名为postgres的用户帐户,该帐户与默认的Postgres角色相关联。 为了使用Postgres,您可以登录该帐户。

There are a few ways to utilize this account to access Postgres.

有几种方法可以使用该帐户访问Postgres。

切换到postgres帐户 (Switching Over to the postgres Account)

Switch over to the postgres account on your server by typing:

通过输入以下命令切换到服务器上的postgres帐户:

  • sudo -i -u postgres

    须藤-i -u postgres

You can now access the PostgreSQL prompt immediately by typing:

现在,您可以通过输入以下内容立即访问PostgreSQL提示符:

  • psql

    psql

From there you are free to interact with the database management system as necessary.

从那里,您可以根据需要自由与数据库管理系统进行交互。

Exit out of the PostgreSQL prompt by typing:

通过输入以下命令退出PostgreSQL提示符:

<
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值