相关文章推荐
文质彬彬的蟠桃  ·  了解适用于Aurora ...·  2 天前    · 
文质彬彬的蟠桃  ·  VS ...·  2 天前    · 
小百科  ›  How To Install PostgreSQL 9.6 on Ubuntu 20.04 | Howtodojo
sudo mongodb postgresql
热心肠的冲锋衣
1 年前
Howtodojo
  • About
  • Certifications
  • Guides
  • Sample Database
  • Cheatsheet
  • Posts
  • Introduction
  • Prerequisites
  • Step 1 — Update Base Systems
  • Step 2 — Import Repository Signing Key
  • Step 3 — Add PostgreSQL 9.6 repository
  • Step 4 — Install PostgreSQL 9.6
  • Verify PostgreSQL 9.6 Installation on Ubuntu 20.04
  • Check PostgreSQL 9.6 Listening Ports
  • Checking PostgreSQL Process
  • Managing PostgreSQL 9.6 Services on Ubuntu 20.04
  • Connect to PostgreSQL using psql
  • Change postgres User Password
  • Uninstall PostgreSQL 9.6 from Ubuntu 20.04
  • PostgreSQL 9.6 References
  • Conclusion


Spring 2022 Promo
Categories
  • Infographics 1
  • Lists 3
  • References 1
  • Security 1
  • Troubleshooting 188
  • Tutorial 297
Tags
  • Amazon EC2 1
  • AWS 1
  • AWS Command Line Interface 1
  • aws-rds-postgresql 1
  • AWS Tutorial 2
  • Bionic Beaver 2
  • caching 2
  • CentOS 4
  • CentOS 6 2
  • CentOS 7 3
  • chkrootkit 1
  • Cloud Images 1
  • Cloujure 1
  • command not found 187
  • Coreutils 106
  • EPEL 2
  • erl 1
  • Erlang 1
  • Erlang OTP 1
  • erlc 1
  • gcc 1
  • git 4
  • GNU Coreutils 106
  • go 1
  • golang 1
  • IBM Java 1
  • IBM Java 7 1
  • IBM JDK 7 1
  • IBM JRE 7 1
  • in-memory cache 1
  • Install Amazon Corretto 8 1
  • install clojure ubuntu 1
  • install go 1
  • install golang 1
  • install java 11 1
  • install java 11 ubuntu 1
  • install java 11 ubuntu 18.04 1
  • install-java-7 1
  • Install Java 8 2
  • install Java 8 Ubuntu 2
  • Install Java 8 Ubuntu 18.04 1
  • Install Memcached 2
  • Install MongoDB 1
  • Install MongoDB 4.0 1
  • Install MongoDB 4.2 2
  • Install MongoDB 4.4 2
  • Install MongoDB CentOS 1
  • Install MongoDB CentOS 7 1
  • Install MongoDB Ubuntu 5
  • Install MongoDB Ubuntu 16.04 1
  • Install MySQL 1
  • Install MySQL Ubuntu 1
  • Install pip Ubuntu 1
  • Install PostgreSQL 7
  • Install PostgreSQL 10 2
  • Install PostgreSQL 11 1
  • Install PostgreSQL 12 1
  • Install PostgreSQL 13 1
  • Install PostgreSQL 14 1
  • Install PostgreSQL 9.6 1
  • Install PostgreSQL Ubuntu 1
  • Install rkhunter 1
  • install rkhunter ubuntu 1
  • install spotify ubuntu 2
  • Install Vagrant 1
  • Install VirtualBox 2
  • install virtualenv 1
  • install virtualenv ubuntu 1
  • install zoom 1
  • IUS 1
  • IUS repository 2
  • Java 2
  • Java 7 1
  • Java 8 1
  • jdk 1
  • JDK8 1
  • Julialang 1
  • libevent 2
  • MacOS X 1
  • memcached 6
  • MongoDB 1
  • MongoDB 3.4 1
  • MongoDb 4.0 1
  • MongoDB 4.4 2
  • MySQL 3
  • MySQL 5.5 1
  • MySQL 5.7 1
  • MySQL 8.0 1
  • netlify 1
  • nim 1
  • nodejs 1
  • OpenJDK 7 1
  • Oracle Java 1
  • Oracle Java 7 1
  • Oracle VirtualBox 2
  • pgbadger 1
  • pip 1
  • PostgreSQL 5
  • PostgreSQL 10 2
  • Python 2
  • python 2 1
  • Redis 2
  • rkhunter 1
  • rootkit 1
  • rust 1
  • rustlang 1
  • security tools 1
  • Skype 2
  • trusty tahr 3
  • Ubuntu 7
  • ubuntu 14.04 3
  • Ubuntu 16.04 20
  • ubuntu 18.04 4
  • Ubuntu 20.04 6
  • Ubuntu Cloud 1
  • Ubuntu Cloud Images 1
  • Ubuntu LTS 2
  • util-linux 83
  • Vagrant 1
  • VirtualBox 2
  • virtualenv 1
  • xcode 1
  • Xenial Xerus 14
  • zoom 2
  • zoom meeting 1
  • zoom webinar 1

How To Install PostgreSQL 9.6 on Ubuntu 20.04

By Muhammad Panji | 2021.07.01
Tags:
  • Install PostgreSQL
  • Install PostgreSQL 9.6
  • PostgreSQL
Categories:
  • Tutorial

Introduction

In this tutorial, we learn how to install PostgreSQL 9.6 on Ubuntu 20.04 (Focal Fossa).

PostgreSQL, or usually called Postgres, is an open-source object-relational database management system (ORDBMS) with an emphasis on extensibility and standards compliance.

PostgreSQL is ACID -compliant and transactional. It is developed by PostgreSQL Global Development Group (PGDG) that consists of many companies and individual contributors. PostgreSQL released under the terms of PostgreSQL license.

PostgreSQL 9.6 was released on 29 September 2016. Major enhancements in PostgreSQL 9.6 includes:

  • Scale up with parallel query
  • Scale Out with Synchronous Replication and postgres_fdw
  • Better Text Search with Phrases
  • Smoother, Faster, and Easier to Use
  • New system views and functions: pg_stat_wal_receiver, pg_visibility, pg_config, pg_blocking_pids, pg_notification_queue_usage
  • Command progress reporting support
  • Cascade support for installing extensions
  • pg_basebackup concurrency and replication slot support
  • Wait Event support
  • View editing and crosstabs in psql
  • User-defined expiration for old snapshots
  • Index-only scans for partial indexes

⚠️ PostgreSQL 9.6 will reach end of life (EOL) on November 11, 2021. You might want to use newer version of PostgreSQL like PostgreSQL 10, PostgreSQL 11 , PostgreSQL 12 , or PostgreSQL 13

Prerequisites

This tutorial assume you already satisfy the following requirements:

  • A machine with fresh install of Ubuntu Server 20.04. It can be A virtual machine locally using Virtualbox, VMWare workstation or VMWare Fusion, KVM, Xen, or a virtual machine in the cloud like DigitalOcean or Linode .
  • A non-root user with sudo privileges (recommended) or a root user access. If you’re using root user remove sudo from each command on this tutorial.

Step 1 — Update Base Systems

Since this is a fresh install of Ubuntu Server 20.04, before we install PostgreSQL 9.6, let’s update our system to the latest update.


sudo apt-get update
sudo apt-get -y upgrade

After we upgrade our base system, now it’s time to install PostgreSQL 9.6.

Since Ubuntu 20.04 doesn’t have PostgreSQL 9.6 in its repository , we need to add oficial PostgreSQL repository so we can install PostgreSQL 9.6.

Step 2 — Import Repository Signing Key

The PostgreSQL team is using GPG to sign downloadable packages from the PostgreSQL website.

We add PostgreSQL public GPG key so apt can verify that packages downloaded from PostgreSQL repository are not tampered or corrupt.

Add PostgreSQL GPG public key using the command below.

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

You should get OK output for command above.

If you got the different output, you need to fix the error first before continue to the next step.

Step 3 — Add PostgreSQL 9.6 repository

After adding PostgreSQL release keys, we create a new repository configuration for PostgreSQL using the command below.

echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql-pgdg.list > /dev/null

Refresh apt metadata using the command below.

sudo apt-get update

Step 4 — Install PostgreSQL 9.6

We’re ready to install PostgreSQL 9.6. Use the command below to install PostgreSQL 9.6 on Ubuntu 20.04.

sudo apt-get install postgresql-9.6

Only 4 steps needed to install PostgreSQL 9.6 on Ubuntu 20.04. We learn how to check and verify and managing PostgreSQL 9.6 installation in the next few sections.

Verify PostgreSQL 9.6 Installation on Ubuntu 20.04

We can check PostgreSQL 9.6 packages that already installed using the command below.


dpkg -l | grep postgresql

Check PostgreSQL 9.6 Listening Ports

By default, PostgreSQL listens on port 5432. We can use netstat to check whether there is a process listening on port 5432.


sudo netstat -naptu | grep 5432

Another method is to check whether there is a process named postgres listening on a port.


sudo netstat -naptu | grep postgres

Alternative to netstat , We can use ss command below to check whether there is a process listen on PostgreSQL default port 5432.


sudo ss -atnp | grep 5432

We can also use ss to check whether there is a process named postgres listening on a port.


sudo ss -atp | grep postgres

The last output above shows there is also a connection to ephemeral UDP port from local. According to this thread on PostgreSQL mailing lists , this is PostgreSQL stats collector that use UDP to send and receive stats data locally.

Checking PostgreSQL Process

We can ue ps command to check what processes currently running with name contain postgres.


ps -aux | grep postgres

Check PostgreSQL 9.6 resource usage like CPU and memory using top command.


top -u postgres

Managing PostgreSQL 9.6 Services on Ubuntu 20.04

Check postgres service status using command below.


sudo service postgresql status

We can also use systemctl command to check PostgreSQL service status.


sudo systemctl status postgresql

Using both commands above you see active (exited) on the Active: line. This happens because systemd doesn’t know the status of each PostgreSQL cluster running on the instance. One instance / installation of PostgreSQL can run mutliple clusters od PostgreSQL.

We can check, list of PostgreSQL clusters running on our machine using the command below.


pg_lsclusters

There is one cluster running on our machine. The cluster named main running PostgreSQL 9.6. To check this cluster service status, we can use the command below.


sudo service [email protected] status

As an alternative to service, we can use systemctl to check this cluster status.


sudo systemctl status [email protected]

Stop PostgreSQL service using the command below.


sudo systemctl stop postgresql

Start PostgreSQL service using the command below.


sudo systemctl start postgresql

Restart PostgreSQL service using the command below.


sudo systemctl restart postgresql

Reload PostgreSQL service using the command below.


sudo systemctl reload postgresql

Connect to PostgreSQL using psql

Now let’s connect to the PostgreSQL 9.6 server using psql client application.

By default, postgres create system user named postgres . There is also role in postgresql database named postgres wth superuser permission.

Switch to postgresql user.


sudo su - postgres

After switching to postgres user, we can connect using psql command.

To list all databases in PostgreSQL we can use \l command.

To list all users in PostgreSQL we can use \du command.

To exit from psql we can use \q command.

To exit from postgres user type exit or CTRL+D

Change postgres User Password

Now we’re on our own linux user. Let’s try to login to localhost or 127.0.0.1 .


$ psql -U postgres -W -h 127.0.0.1
Password for user postgres: 

It prompts for a password. Since we haven’t set any password, let’s leave it empty. We get the error message below.


psql: fe_sendauth: no password supplied

Since we cannot login without providing password, we set new password for postgres user. Change user to postgres user like shown above and use psql to connect to PostreSQL.

After logging in, type \password . Enter new password and confirmation password for user postgres .

When we login again to localhost or 127.0.0.1 and provide a password, we can log in successfully.

Uninstall PostgreSQL 9.6 from Ubuntu 20.04

In this section, we learn how to uninstall PostgreSQL 9.6 and its dependencies on Ubuntu 20.04 completely.

Please be careful when running steps in this section since this will stop your PostgreSQL database server.

You can use the command below to uninstall all PostgreSQL 9.6 packages, both server, and client.

sudo apt-get remove postgresql-9.6 \
    postgresql-client-9.6 \
    postgresql-client-common \
    postgresql-common
 
推荐文章
文质彬彬的蟠桃  ·  了解适用于Aurora PostgreSQL 的Babelfish 中的排序规则- Amazon ...
2 天前
文质彬彬的蟠桃  ·  VS Code官方新PostgreSQL擴充功能整合Copilot,輔助撰寫與最佳化 ...
2 天前
Link管理   ·   Sov5搜索   ·   小百科
小百科 - 百科知识指南