what difference between privileges in posgtresql? - postgresql

new on postgresql DBMS.
after a \l command we have an output similar of this:
postgres | postgres | UTF8 | it_IT.UTF-8 | it_IT.UTF-8 |
template0 | postgres | UTF8 | it_IT.UTF-8 | it_IT.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | it_IT.UTF-8 | it_IT.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
After I create a role named root and grant it superuser privileges I get this output:
postgres | postgres | UTF8 | it_IT.UTF-8 | it_IT.UTF-8 |
root | root | UTF8 | it_IT.UTF-8 | it_IT.UTF-8 | =Tc/root +
| | | | | **root=C*T*c*/root**
template0 | postgres | UTF8 | it_IT.UTF-8 | it_IT.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | it_IT.UTF-8 | it_IT.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
My question is, what's difference between CTc and C*T*c* ?

Related

How to add multiple Access privileges in Postgres

currently i have Access privileges like below
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
----------------------+----------------+----------+---------+---------+------------------------------------
core_db | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres
core_db_20221228 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | coredbuser=CTc/postgres
postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
i want this kind of Access privileges
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
----------------------+----------------+----------+---------+---------+------------------------------------
core_db | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | coredbuser=CTc/postgres
core_db_20221228 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | coredbuser=CTc/postgres
postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
How to add multiple Access privileges in Postgres
As user postgres run the following:
GRANT ALL PRIVILEGES ON DATABASE "core_db" to coredbuser;
This will grant to user coredbuser the following privileges on database core_db:
CREATE C
TEMPORARY T
CONNECT c

Postgres cannot create database but can create a user

I am using Ubuntu Linux. I am trying to use Postgres as database. It is doing fine when I created a user:
CREATE USER username;
But when I try to create a database, it returns nothing:
CREATE DATABASE databasename;
What is happening with my Postgres?
datid | datname | pid | leader_pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | xact_start | query_start | state_change | wait_event_type | wait_event | state | backend_xid | backend_xmin | query_id | query | backend_type
-------+----------+------+------------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------------+---------------------+--------+-------------+--------------+----------+---------------------------------+------------------------------
| | 8237 | | | | | | | | 2022-02-02 13:00:47.683187+07 | | | | Activity | AutoVacuumMain | | | | | | autovacuum launcher
| | 8239 | | 10 | postgres | | | | | 2022-02-02 13:00:47.70127+07 | | | | Activity | LogicalLauncherMain | | | | | | logical replication launcher
13726 | postgres | 8329 | | 10 | postgres | psql | | | -1 | 2022-02-02 13:08:52.250244+07 | 2022-02-02 13:09:10.651383+07 | 2022-02-02 13:09:10.651383+07 | 2022-02-02 13:09:10.651393+07 | Lock | object | active | | 740 | | CREATE DATABASE kong; | client backend
13726 | postgres | 8313 | | 10 | postgres | psql | | | -1 | 2022-02-02 13:04:57.265085+07 | 2022-02-02 13:10:40.097817+07 | 2022-02-02 13:10:40.097817+07 | 2022-02-02 13:10:40.09782+07 | | | active | | 740 | | SELECT * FROM pg_stat_activity; | client backend
| | 8235 | | | | | | | | 2022-02-02 13:00:47.664058+07 | | | | Activity | BgWriterHibernate | | | | | | background writer
| | 8234 | | | | | | | | 2022-02-02 13:00:47.654713+07 | | | | Activity | CheckpointerMain | | | | | | checkpointer
| | 8236 | | | | | | | | 2022-02-02 13:00:47.673631+07 | | | | Activity | WalWriterMain | | | | | | walwriter
(7 rows)
(END)
and for the pg_locks
locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath | waitstart
------------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+------+------------------+---------+----------+-------------------------------
relation | 13726 | 12290 | | | | | | | | 7/17 | 8313 | AccessShareLock | t | t |
virtualxid | | | | | 7/17 | | | | | 7/17 | 8313 | ExclusiveLock | t | t |
virtualxid | | | | | 3/15 | | | | | 3/15 | 8329 | ExclusiveLock | t | t |
virtualxid | | | | | 6/12 | | | | | 6/12 | 8335 | ExclusiveLock | t | t |
virtualxid | | | | | 5/3 | | | | | 5/3 | 8266 | ExclusiveLock | t | t |
virtualxid | | | | | 4/1 | | | | | 4/1 | 8264 | ExclusiveLock | t | t |
object | 0 | | | | | | 1262 | 1 | 0 | 6/12 | 8335 | RowExclusiveLock | f | f | 2022-02-02 13:09:30.561821+07
object | 0 | | | | | | 1262 | 1 | 0 | 3/15 | 8329 | ShareLock | f | f | 2022-02-02 13:09:10.651571+07
object | 0 | | | | | | 1262 | 1 | 0 | 4/1 | 8264 | RowExclusiveLock | t | f |
relation | 0 | 1262 | | | | | | | | 3/15 | 8329 | AccessShareLock | t | f |
object | 0 | | | | | | 1262 | 1 | 0 | 5/3 | 8266 | RowExclusiveLock | t | f |
(11 rows)
(END)
Database info
postgres=# \l
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description
-----------+----------+----------+---------+---------+-----------------------+---------+------------+--------------------------------------------
postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 | | 8529 kB | pg_default | default administrative connection database
template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +| 8377 kB | pg_default | unmodifiable empty database
| | | | | postgres=CTc/postgres | | |
template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +| 8529 kB | pg_default | default template for new databases
| | | | | postgres=CTc/postgres | | |
(3 rows)
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
kong | | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
postgres=#
Using the same database name and user is not good practice. This may result in various errors.
When you call the command
CREATE DATABASE databaseName;
PostgreSql creates a database. This may take some time. After creating the database, you will receive a message:
CREATE DATABASE
postgres=#
Problem solved by reinstalling the pg to its old version (was installed 14, downgrade to 12 and it solved). Thanks to everyone here who helped me

Two database with the same name - how to dump?

I have two database with the same name after a manipulation error (I think).
When I try to dump the one owned by bussiere it always dumps the empty one owned by postgres.
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+-------+-----------------------
dbbiotech | bussiere | SQL_ASCII | C | C |
ddbiotech | postgres | SQL_ASCII | C | C | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | bussiere=CTc/postgres
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
You don't. The name is different: dbbiotech is not ddbiotech.
Looks like a misunderstanding. It wouldn't be possible to have the same name twice in the same DB cluster to begin with. Postgres does not allow it.

PostgreSQL - No relations found.

I’m totally new to developer world, so I apologize if I’m not make my question clearly, please don’t be hesitate to point out if I did any wrong. Thanks.
I faced this problem on setting my PostgreSQL DB, no relations found when type command timlin=# \d.
I did try below solution to fix but it didn’t work.
postgresql database owner can't access database - "No relations found."
Below is my situation
timlin=# \dn+
List of schemas
Name | Owner | Access privileges | Description
--------+--------+-------------------+————————————
public | timlin | timlin=UC/timlin +| standard public schema
| | =UC/timlin |
(1 row)
timlin=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------------+--------+----------+-------------+-------------+--------------------
postgres | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
psqlapp | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
psqlapp_development | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
psqlapp_test | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
psqlappdemo | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/timlin +
| | | | | timlin=CTc/timlin +
| | | | | psqlapp=CTc/timlin
template0 | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/timlin +
| | | | | timlin=CTc/timlin
template1 | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/timlin +
| | | | | timlin=CTc/timlin
timlin | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(8 rows)
timlin=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
psqlapp | | {}
timlin | Superuser, Create role, Create DB, Replication | {}
I check each one and couldn't find any difference between previous soultion.
While I try
timlin=# \d
I still got the result :
No relations found.
What do I missed ? How can I fix it ?
Please advice and thank you all in advence.
This would imply that the database timlin does not contain any tables in the public schema (which is what \d would normally list).
It sounds like you created an empty database, e.g.:
createdb -h localhost -U postgres timlin
In which case, immediately after creation, \d would return:
No relations found.
You would need to explicitly create one or more tables in order to see anything listed in the output of \d.
e.g. if you do the following:
create table foo (id serial, val text);
And then do a \d, the following output will result:
List of relations
Schema | Name | Type | Owner
--------+------------+----------+----------
public | foo | table | postgres
public | foo_id_seq | sequence | postgres
(2 rows)

Can see tables in phpPgAdmin but not in psql (or any other method)

I have recently installed postgres on my Mac and loaded a dump from our public website that I am trying to replicate locally. The pg_restore appeared to be successful, and I can see all my tables and user permissions in phpPgAdmin. They all look normal, and I can browse the data. However, when I access the database via psql I get no relations found. Similarly I have python scripts that access this database, and they also fail to find any tables.
I'm at a loss as to what to do.
Here are some psql commands I've done:
> psql -U mgd_dbo pub_mgd
psql (9.3.4)
Type "help" for help.
pub_mgd=# \d
No relations found.
pub_mgd=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+------------+----------+------------------+-------+-------------------------
postgres | postgres | UTF8 | C | C | =CTc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | mgd_dbo=CTc/postgres +
| | | | | mgd_public=CTc/postgres
pub_fe | postgres | LATIN9 | en_US.ISO8859-15 | C | =CTc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | mgd_dbo=CTc/postgres +
| | | | | mgd_public=CTc/postgres
pub_mgd | postgres | LATIN9 | en_US.ISO8859-15 | C | =CTc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | mgd_dbo=CTc/postgres +
| | | | | mgd_public=CTc/postgres
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)
pub_mgd=# \dn+
List of schemas
Name | Owner | Access privileges | Description
--------+----------+----------------------+------------------------
mgd | mgd_dbo | mgd_dbo=UC/mgd_dbo +|
| | mgd_public=U/mgd_dbo |
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
(2 rows)
pub_mgd is the database I've loaded. mgd_public and mgd_dbo are the two different users our scripts use (mgd_public is a read-only user).
I've tried both users, and even as the postgres user. Yet, the results are the same, no relations.
I even tried to see if phpPgAdmin was somehow hitting a different postgres sever, so I added a new database through it, and verified that the new database appears when I do \l in psql.
Any suggestions as to what to check next?
Ask for the list of relations in the mgd schema
\d mgd.*
To make the mgd schema the default place it at the beginning of the search path
set search_path to mgd, "$user", public;