How to Change Owner View in PostgreSQL Database

Posted on

By looking in the title of the article, the main subject of this article is definitely clear. It is about how to change the owner of a view in PostgreSQL Database. It is a simple administration task in almost generally any type of database. In order to change the owner of the view exist in PostgreSQL Database, there are several steps to accomplish it. The following are those steps to fulfill the tasks :

1. Just access the PostgreSQL Database. Accessing PostgreSQL Database is possible by typing a certain command. Fortunately, in this article, accessing PostgreSQL Database is quite simple. Just type the following command in the command line :

user@hostname:~$ psql -Upostgres dbname
psql (10.5)
Type "help" for help.
dbname=#

The above command is a command to connnect to the PostgreSQL Database. Precisely, to connect to the PostgreSQL Command Line Console. Using the additional parameter -U for passing user value, and the next parameter for the database, do it so that the connection to the PostgreSQL Database is a success.

2. After successfully connect to the database, first of all check the available view by typing the following command :

dbname=# \dv
                List of relations
 Schema |         Name          | Type |  Owner   
--------+-----------------------+------+----------
 public | view_xxxxxx           | view | postgres
 public | view_xxxxxx           | view | postgres
 ...
 public | view_xxxxxx           | view | postgres
(18 rows)
dbname=#

So, in order to list the command it is quite simple. Just type ‘\dv’ in PostgreSQL Command Console. Do it after connecting to the associated database.

3.Type the following query in the PostgreSQL Command Line Console to alter the owner of a view. Just type the following command :

dbname=# alter view view_test owner to postgres;
ALTER VIEW
dbname=# 

To show the change of the owner, just retype the previous command for listing the available views in the database. Pretty much the above steps are the steps for changing the owner of a view in PostgreSQL Database. The pattern for changing the owner of a view as follows :

ALTER VIEW view_name OWNER TO user_name;

Leave a Reply