How to move tables from one schema to another in PostgreSQL

In this article, we will see how to move tables from one schema to another in PostgreSQL. We can move the tables from one schema to another by using alter table command. Schemas are database objects. Same schema can be exists in different. But, tables of schema are different.

Syntax:

ALTER TABLE table_name SET SCHEMA schema_name;

Examples to move tables from one schema to another in PostgreSQL:
Continue reading How to move tables from one schema to another in PostgreSQL

How to take backup and restore table in PostgreSQL

In this article, we are going to how to take backup and restore table in PostgreSQL. We use pg_dump to take backup of table wiht –table option and psql or pg_restore tools are used to restore the table using existing backup.

1. Syntax to backup table data:

pg_dump -Fc --data-only -h -p -U -W -d -t

> /path_and_filename_forbackup

Continue reading How to take backup and restore table in PostgreSQL

How to find list tables in a PostgreSQL schema

In this article, we will see how to find list tables in a PostgreSQL schema with examples.

We can find the list of tables in a PostgreSQL schema using meta-command or by using SQL statement by querying against table pg_tables.

Find list tables in a PostgreSQL schema using meta-command: Continue reading How to find list tables in a PostgreSQL schema

PostgreSQL describe table

In this article, we will see PostgreSQL describe table. Which means we will get the table structure in of PostgreSQL table.

We can get the table structure by using meta command select query.

PostgreSQL describe table using meta command:
Continue reading PostgreSQL describe table

How to get top 10 tables in PostgreSQL Server database

In this article, we are going to find out the top 10 tables in PostgreSQL Database by SQL query.

To get top 10 tables in PostgreSQL Server database:

SELECT table_name ,pg_relation_size(table_schema || '.' || table_name) as size FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'pg_catalog') ORDER BY size DESC LIMIT 10;

Output:

table_name | size ------------+------ stock | 8192 orderline | 8192 barcode | 8192 customer | 8192 item | 8192 orderinfo | 0 (6 rows)

To get top 5 tables in PostgreSQL Server database:

SELECT table_name ,pg_relation_size(table_schema || '.' || table_name) as size FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'pg_catalog') ORDER BY size DESC LIMIT 5;

Output:

table_name | size ------------+------ stock | 8192 orderline | 8192 barcode | 8192 customer | 8192 item | 8192 (5 rows)

How to get list of tables in PostgreSQL Database

We can get the list of tables by using the meta-command \dt or by using SQL statement.

Get the list of tables in current schema of PostgreSQL by using \dt:

How to get list of tables in PostgreSQL Database
How to get list of tables in PostgreSQL Database

Get the list of tables in PostgreSQL by using SQL statement:
Continue reading How to get list of tables in PostgreSQL Database