List all databases in PostgreSQL psql

Quick bite




to list all databases

\connect {databasename}

to connect to database


to list tables in current database

psql is interactive frontend for PstgreSQL using which you can connect you postgres database and execute commands and SQL. The commands listed above fall under category meta commands.
More information can be found in psql documentation


How to do UPSERT query in PostgreSQL

WITH upsert AS (<update-query-here> RETURNING *) <insert-query-here>  WHERE NOT EXISTS (SELECT * FROM upsert);

<insert-query-here> Should be of form
“INSERT INTO table_name (column1, column2, …) SELECT ‘column_1_value’, ‘column_2_value’, …”
Hence if update query succeeds, insert query wont execute due to WHERE clause.

Thanks to reference

Get System Information in Ubuntu

Quick bite

uname -a

uname is command which can be used to get system information on Linux/Unix OS.
Other options can be used to get specific information about current system.
-s, –kernel-name
print the kernel name, 
-r, –kernel-release print the kernel release
-v, –kernel-version print the kernel version
-m, –machine print the machine hardware name
-p, –processor print the processor type
-i, –hardware-platform print the hardware platform
-o, –operating-system print the operating system

For More options