Skip to main content

PostgreSQL Daliy | PosgteSQL adninistration

List databases:

postgres-# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 test      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)

Connect to database:
postgres-# \connect postgres
You are now connected to database "postgres" as user "postgres".

List schema:
postgres-# \dn[S+]
 information_schema | postgres | postgres=UC/postgres+|
                    |          | =U/postgres          |
 pg_catalog         | postgres | postgres=UC/postgres+| system catalog schema
                    |          | =U/postgres          |
 pg_temp_1          | postgres |                      |
 pg_toast           | postgres |                      | reserved schema for TOAST tables
 pg_toast_temp_1    | postgres |                      |
 public             | postgres | postgres=UC/postgres+| standard public schema
                    |          | =UC/postgres         |
Roles:
postgres-#  \dg[S+]
 pg_execute_server_program | Cannot login                                               | {}                                                           |
 pg_monitor                | Cannot login                                               | {pg_read_all_settings,pg_read_all_stats,pg_stat_scan_tables} |
 pg_read_all_settings      | Cannot login                                               | {}                                                           |
 pg_read_all_stats         | Cannot login                                               | {}                                                           |
 pg_read_server_files      | Cannot login                                               | {}                                                           |
 pg_signal_backend         | Cannot login                                               | {}                                                           |
 pg_stat_scan_tables       | Cannot login                                               | {}                                                           |
 pg_write_server_files     | Cannot login                                               | {}                                                           |
 postgres                  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}   
 
postgres-# \connect postgres
You are now connected to database "postgres" as user "postgres".

List tables of the database postgres:
postgres-# \dt[S+]
 pg_catalog | pg_aggregate            | table | postgres | 56 kB      |
 pg_catalog | pg_am                   | table | postgres | 40 kB      |
 pg_catalog | pg_amop                 | table | postgres | 80 kB      |
 pg_catalog | pg_amproc               | table | postgres | 56 kB      |
 pg_catalog | pg_attrdef              | table | postgres | 8192 bytes |
 pg_catalog | pg_attribute            | table | postgres | 464 kB     |
 pg_catalog | pg_auth_members         | table | postgres | 40 kB      |
 pg_catalog | pg_authid               | table | postgres | 48 kB      |
 pg_catalog | pg_cast                 | table | postgres | 48 kB      |
 pg_catalog | pg_class                | table | postgres | 136 kB     |
 pg_catalog | pg_collation            | table | postgres | 424 kB     |
 pg_catalog | pg_constraint           | table | postgres | 48 kB      |
 pg_catalog | pg_conversion           | table | postgres | 56 kB      |
 pg_catalog | pg_database             | table | postgres | 48 kB      |
 pg_catalog | pg_db_role_setting      | table | postgres | 8192 bytes |
 pg_catalog | pg_default_acl          | table | postgres | 8192 bytes |
 pg_catalog | pg_depend               | table | postgres | 480 kB     |
 pg_catalog | pg_description          | table | postgres | 360 kB     |
 pg_catalog | pg_enum                 | table | postgres | 0 bytes    |
 pg_catalog | pg_event_trigger        | table | postgres | 8192 bytes |
 pg_catalog | pg_extension            | table | postgres | 48 kB      |
 pg_catalog | pg_foreign_data_wrapper | table | postgres | 8192 bytes |
 pg_catalog | pg_foreign_server       | table | postgres | 8192 bytes |
 pg_catalog | pg_foreign_table        | table | postgres | 8192 bytes |
 pg_catalog | pg_index                | table | postgres | 64 kB      |
 pg_catalog | pg_inherits             | table | postgres | 0 bytes    |
 pg_catalog | pg_init_privs           | table | postgres | 56 kB      |
 pg_catalog | pg_language             | table | postgres | 48 kB      |
 pg_catalog | pg_largeobject          | table | postgres | 0 bytes    |
 pg_catalog | pg_largeobject_metadata | table | postgres | 0 bytes    |
 pg_catalog | pg_namespace            | table | postgres | 48 kB      |
 pg_catalog | pg_opclass              | table | postgres | 48 kB      |
 pg_catalog | pg_operator             | table | postgres | 144 kB     |
 pg_catalog | pg_opfamily             | table | postgres | 48 kB      |
 pg_catalog | pg_partitioned_table    | table | postgres | 8192 bytes |
 pg_catalog | pg_pltemplate           | table | postgres | 48 kB      |
 pg_catalog | pg_policy               | table | postgres | 8192 bytes |
 pg_catalog | pg_proc                 | table | postgres | 672 kB     |
 pg_catalog | pg_publication          | table | postgres | 0 bytes    |
 pg_catalog | pg_publication_rel      | table | postgres | 0 bytes    |
 pg_catalog | pg_range                | table | postgres | 40 kB      |
 pg_catalog | pg_replication_origin   | table | postgres | 8192 bytes |
 pg_catalog | pg_rewrite              | table | postgres | 632 kB     |
 pg_catalog | pg_seclabel             | table | postgres | 8192 bytes |
 pg_catalog | pg_sequence             | table | postgres | 0 bytes    |
 pg_catalog | pg_shdepend             | table | postgres | 40 kB      |
 pg_catalog | pg_shdescription        | table | postgres | 48 kB      |
 pg_catalog | pg_shseclabel           | table | postgres | 8192 bytes |
 pg_catalog | pg_statistic            | table | postgres | 256 kB     |
 pg_catalog | pg_statistic_ext        | table | postgres | 8192 bytes |
 pg_catalog | pg_statistic_ext_data   | table | postgres | 8192 bytes |
 pg_catalog | pg_subscription         | table | postgres | 8192 bytes |
 pg_catalog | pg_subscription_rel     | table | postgres | 0 bytes    |
 pg_catalog | pg_tablespace           | table | postgres | 48 kB      |
 pg_catalog | pg_transform            | table | postgres | 0 bytes    |
 pg_catalog | pg_trigger              | table | postgres | 8192 bytes |
 pg_catalog | pg_ts_config            | table | postgres | 40 kB      |
 pg_catalog | pg_ts_config_map        | table | postgres | 56 kB      |
 pg_catalog | pg_ts_dict              | table | postgres | 48 kB      |
 pg_catalog | pg_ts_parser            | table | postgres | 40 kB      |
 pg_catalog | pg_ts_template          | table | postgres | 40 kB      |
 pg_catalog | pg_type                 | table | postgres | 120 kB     |
 pg_catalog | pg_user_mapping         | table | postgres | 8192 bytes |


Comments

Popular posts from this blog

MySQL InnoDB cluster troubleshooting | commands

Cluster Validation: select * from performance_schema.replication_group_members; All members should be online. select instance_name, mysql_server_uuid, addresses from  mysql_innodb_cluster_metadata.instances; All instances should return same value for mysql_server_uuid SELECT @@GTID_EXECUTED; All nodes should return same value Frequently use commands: mysql> SET SQL_LOG_BIN = 0;  mysql> stop group_replication; mysql> set global super_read_only=0; mysql> drop database mysql_innodb_cluster_metadata; mysql> RESET MASTER; mysql> RESET SLAVE ALL; JS > var cluster = dba.getCluster() JS > var cluster = dba.getCluster("<Cluster_name>") JS > var cluster = dba.createCluster('name') JS > cluster.removeInstance('root@<IP_Address>:<Port_No>',{force: true}) JS > cluster.addInstance('root@<IP add>,:<port>') JS > cluster.addInstance('root@ <IP add>,:<port> ') JS > dba.getC...

MySQL 5.7 Install | Configure MySQL | Configure MySQL Replication | Configure systemd for single instance

Install MySQL 5.7 Community Edition on Linux: #yum install mysql80-community-release-el7-1.noarch.rpm #yum install mysql-community-server #yum install perl-DBD-MySQL-4.023-6.el7.x86_64.rpm #yum install percona-release-0.1-4.noarch.rpm Increase no. of open files: Edit file /etc/security/limits.conf and includes as follows, which will increase no of open files for mysql user to 65535 from 1024 which is default. excute ulimit -a after sudo to mysql, if you are logged in exit and login again then and then only you will be able to see it. mysql              soft     nofile           65535 mysql             hard     nofile           65535 Ref.: https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html https://jinyuwang.weebly.co...

Create MySQL database with hyphen

Create MySQL database with hyphen: If you are trying to create MySQL database with hyphen " - " in the name such as test-db and get error  " your MySQL server version for the right syntax to use near '-db' at line" then you might be wondering how to get it done as your business require MySQL database name with hyphen " - "  Here is the fix, use escape character " ` " before and after database name such as `test-db` and you will be able to create database with hyphen. CREATE DATABASE `test-db`;