Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Installing PostgreSQL on Linux

Installing PostgreSQL on Linux

Open the PostgreSQL official website https://www.postgresql.org/, click on the menu bar Download , and you can see that it contains installation packages for many platforms, including Linux, Windows, Mac OS, and more.

For Linux, we can see support for various platforms such as Ubuntu and Red Hat; click a specific platform link to view the installation method:

Click the one in the image above file browser, and we can also download the latest PostgreSQL source code.

This chapter uses Ubuntu as an example.

Installing PostgreSQL on Ubuntu

Ubuntu can install PostgreSQL using apt-get:

sudo apt-get update

sudo apt-get install postgresql postgresql-client

After installation, the system creates a database superuser named postgres with an empty password.

#  sudo -i -u postgres

Then use the following command to enter postgres; the following output indicates a successful installation:

~$ psql

psql (9.5.17)

Type "help" for help.



postgres=# 

Enter the following command to exit the PostgreSQL prompt:

\q

After installation, PostgreSQL is started by default, but you can also start the service manually using the following method.

sudo /etc/init.d/postgresql start   # 开启

sudo /etc/init.d/postgresql stop    # 关闭

sudo /etc/init.d/postgresql restart # 重启