How to exit from PostgreSQL command line utility

If we want to exit from PostgreSQL command line utility, use following commands in the shell.
1) \q
2) exit

How to Change a User to Superuser in PostgreSQL

In this artcile, we will do below 3 steps:

1. Create user
2. View user permissions
3. Alter(change) existing permission.

How to change database owner in PostgreSQL

Owner of the login is the user who created the database. Later, if we want to change the name of the database owner, we can change with alter database db_name owner to new_owner_name;.

Here, we have created the database ‘test’ and enteprisedb is owner of the database. Now, we are changing the owner of the database to k2admin. Please go through 3 steps.

1. To check current of the database.

edb=# \l

List of databases Name | Owner | Encoding | Collate | Ctype | ICU | Access privileges -----------+--------------+----------+-------------+-------------+-----+------------------------------- edb | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | k2info | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | postgres | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | template0 | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | =c/enterprisedb + | | | | | | enterprisedb=CTc/enterprisedb template1 | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | =c/enterprisedb + | | | | | | enterprisedb=CTc/enterprisedb test | enterprisedb

| UTF8 | en_US.UTF-8 | en_US.UTF-8 | | (6 rows)

2. Change the database owner.

To get the PostgreSQL server version

If we experience problems, we need to double check the version of PostgreSQL server. It will help us to report a fault or consult the correct version of manual.

To get the PostgreSQL server version using psql shell:

edb=# select version();
version
——————————————————————————————————————-
EnterpriseDB 9.4.1.3 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55), 64-bit
(1 row)

edb=# show server_version;
server_version
—————-
9.4.1.3
(1 row)

How to get list of tables in PostgreSQL

As a routine database admistration task, administrators used to check the list of databases in the server and list of tables in available in currently connected database. In this tutorial, we will learn how to get list of tables in current connected database.

To get list of tables in list of tables in PostgreSQL database.

1. Connect to the database

\c edb

You are now connected to database “edb” as user “enterprisedb”.

Powered by k2schools