Installing Postgres 12
Guide to installing and configuring PostgreSQL 12 on Debian 10.
Requirements
Operating System | Version |
---|---|
Debian | 10 |
Installation
Refresh the package index.
sudo apt-get update
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
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
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
Install PostgreSQL 12.
sudo apt-get install postgresql-12
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