Installing Postgres 12

Guide to installing and configuring PostgreSQL 12 on Debian 10.

Requirements

Operating SystemVersion
Debian10

Installation

  1. Refresh the package index.

    sudo apt-get update
    
  2. Remove old packages.

    List the packages related to PostgreSQL.

    dpkg -l | grep postgres
    

    Then remove them. For example:

    sudo apt-get --purge remove \
      postgresql \
      postgresql-client \
      postgresql-common
    
  3. Create the pgdg.list file.

    sudo nano /etc/apt/sources.list.d/pgdg.list
    

    Add the following line:

    pgdg.list

    deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main
    
  4. Import the repository key and update the index again.

    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc |
      sudo apt-key add -
    
    OK
    
    sudo apt-get update
    
  5. Install PostgreSQL 12.

    sudo apt-get install postgresql-12
    
  6. Start the PostgreSQL service.

    sudo service postgresql start
    

Verification

Check the installed version.

psql --version
psql (PostgreSQL) 12.3 (Debian 12.3-1.pgdg100+1)

Inspect the service status.

sudo service postgresql status
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since Tue 2020-06-02 20:07:50 -04; 1min 1s ago
  Process: 7390 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 7390 (code=exited, status=0/SUCCESS)
...

Change the Postgres User Password

Open the psql console as the postgres user.

sudo -u postgres psql
psql (12.3 (Debian 12.3-1.pgdg100+1))
Digite «help» para obtener ayuda.

postgres=#

Run the following statement:

ALTER USER postgres WITH PASSWORD '12345678';
ALTER ROLE

Exit the console with \q, then press CTRL + D to leave the superuser session.

\q

Auto-start

Control whether the service starts automatically.

sudo systemctl enable postgresql

To undo the change:

sudo systemctl disable postgresql

References

Published: June 2, 2020