How to connect to Azure PostgreSQL Server

In this article, we will see how to connect to Azure PostgreSQL Server from pgadmin or psql.

1. Steps to connect to Azure PostgreSQL server from pgadmin:

1. Connect to Azure portal, then click on Azure PostgreSQL Server. From left menu click on connection security. Then, provide name for your firewall, IP address as show below. Then click on Save.
Continue reading How to connect to Azure PostgreSQL Server

How to get list of sessions on PostgreSQL database

In this article, we will see how to get list of sessions on PostgreSQL database. We will see all sessions in PostgreSQL and sessions specific to the database. We can get session by running queries against pg_stat_activity.

Syntax to get list of sessions on PostgreSQL database: Continue reading How to get list of sessions on PostgreSQL database

How to take backup and restore table in PostgreSQL

In this article, we are going to how to take backup and restore table in PostgreSQL. We use pg_dump to take backup of table wiht –table option and psql or pg_restore tools are used to restore the table using existing backup.

1. Syntax to backup table data:

pg_dump -Fc --data-only -h -p -U -W -d -t

> /path_and_filename_forbackup

Continue reading How to take backup and restore table in PostgreSQL

How to take backup of a table(s) in PostgreSQL

In this article, we will see how to take backup of a table(s) in PostgreSQL. We can take the backup of single or multiple tables using pg_dump command with –table or -t option.

Syntax to take backup of table(s) in PostgreSQL:

Following syntax is used to take backup of table with table definition:

pg_dump -d databasename --table=yourTable --column-inserts > file_name.sql

Continue reading How to take backup of a table(s) in PostgreSQL

psql: could not connect to server: Connection refused

In this article, we will the solution for below error.

psql: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

psql could not connect to server Connection refused
Continue reading psql: could not connect to server: Connection refused

psql: FATAL: the database system is starting up

In this article, we will the solution for below error.

psql: FATAL: the database system is starting up

psql FATAL the database system is starting up

Continue reading psql: FATAL: the database system is starting up

How to find the name of the current database from within PostgreSQL?

In this article, we will see how to find the name of the current database from within PostgreSQL.

We can get the current database in PostgreSQL by using below commands

select current_database(); \c \conninfo SELECT * FROM current_catalog;

Continue reading How to find the name of the current database from within PostgreSQL?

How to save query result to a file in PostgreSQL

In this article, we will see how to save query result to a file in PostgreSQL. We can save query result to txt, csv,.. files.

We have three methods to save/export query results to a file in PostgreSQL:

1) copy command
2) from Linux shell using psql tool.
3) \o method.

Continue reading How to save query result to a file in PostgreSQL

bash psql command not found

After installation of PostgreSQL on MAC OS, when tried to connect to PostgreSQL using psql tool then received error:

bash: psql: command not found

bash psql command not found

Steps to fix this issue:
Continue reading bash psql command not found