![PostgreSQL](https://serverok.in/wp-content/uploads/2019/02/PostgreSQL.png)
PostgreSQL connect to database using psql
To connect to PostgreSQL database server using psql command line, run su – postgres psql If you have a PostgreSQL
![postgresql.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files](https://serverok.in/wp-content/themes/understrap-child/images/default.webp)
postgresql.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files
When i restart postgresql, i get following error postgres@vmi465483:~$ systemctl restart postgresql.service Failed to restart postgresql.service: The name org.freedesktop.PolicyKit1 was
![PostgreSQL](https://serverok.in/wp-content/uploads/2019/02/PostgreSQL.png)
PostgreSQL Export table into CSV file
To export a table into CSV file, run \copy TABLE_NAME to ‘FILE_NAME.csv’ csv header; This will save the CSV file
![PostgreSQL](https://serverok.in/wp-content/uploads/2019/02/PostgreSQL.png)
PostgreSQL List all databases
To list all databases in PostgreSQL database, first connect to PostgreSQL database using psql command su – postgres psql Now
![PostgreSQL Create Database](https://serverok.in/wp-content/themes/understrap-child/images/default.webp)
PostgreSQL Create Database
To create a database, run CREATE DATABASE “DB_NAME_HERE”; Creating user, grant permissions CREATE USER USER_NAME_HERE WITH PASSWORD ‘BAPT788HZutBdV’; GRANT ALL
![PostgreSQL drop database](https://serverok.in/wp-content/uploads/2018/11/postgresql-drop-database.png)
PostgreSQL Delete a Database
To delete a PostgreSQL database, run DROP DATABASE DB_NAME; Example DROP DATABASE “odoodb2”;
![pg_ctl](https://serverok.in/wp-content/themes/understrap-child/images/default.webp)
pg_ctl
pg_ctl is used to start, stop PostgreSQL server. To start PostgreSQL, run pg_ctl start -D /path/to/datadir You can also use