home scroll postgres

Postgres

Main site

https://www.postgresql.org/

Install Postgre on Ubuntu 22.04

Installs the latest version:
https://www.digitalocean.com/community/tutorials/how-to-install-postgresql-on-ubuntu-22-04-quickstart
sudo apt install postgresql postgresql-contrib
Check status:
systemctl status postgresql


This installs an older version but Also explains how to allow access from connections other than localhost:
Configure remote Connection
https://computingforgeeks.com/how-to-install-postgresql-13-on-ubuntu/

Using Postgres

The installation automatically creates a user named postgres.
Login as default user postgres
sudo -i -u postgres
On command line, to change the password of the default user:
psql -c "alter user postgres with password 'StrongAdminP@ssw0rd'"
On command line, access the Postgres prompt:
psql
The terminal will now show the name of the user who entered the Postgre prompt:
postgres=#
Exit the Postgre prompt:
\q
Create a new database:
On the postgres user's command prompt:
createdb sammy
Show databases:
\l
To list the tables in a database, first connect to the database:
\c sammy
Then
\dt
get specific information about a table named todos:
\d+ todos
to show the contents of a table named todos:
SELECT * FROM todos;
Note: The query has to be upper-case and have the semi-colon at the end.

Create a new user:
sudo -u postgres createuser --interactive
For Example:
Enter name of role to add: sammy
Shall the new role be a superuser? (y/n) y
To be able to use Postgre with this new user, need to make admin
sudo adduser sammy

Install pgadmin4 (phpadmin - like interface)

with nginx:
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-pgadmin-4-in-server-mode-on-ubuntu-22-04
with Apache:
https://computingforgeeks.com/how-to-install-pgadmin-4-on-ubuntu/

Connect to the admin tool:
http://127.0.0.1/pgadmin4

Set Authentication Method

Modify the configuration file
sudo nano /etc/postgresql/14/main/pg_hba.conf
and change authentication method, for example to password:
# IPv4 local connections:
host all all 127.0.0.1/32 password
and restart Postgres
sudo systemctl restart postgresql
Where are the Postgres log files located?
ls /var/log/postgresql

Category

git Usage

Single Board Computers

Follow Me

Some text..