PostgreSQL sample database

In this article, we will see how to download and restore PostgreSQL sample database in PostgreSQL server. We can use PostgreSQL sample database for learning and practice PostgreSQL. We will use the DVD rental database for demonstrating the features of PostgreSQL.

The DVD rental database has many objects including tables, views, trigger, functions, sequences and domain.

Download the PostgreSQL Sample database

Continue reading PostgreSQL sample database

How to Copy table from one database to another in PostgreSQL

In this article, we will see how to Copy table from one database to another in PostgreSQL. We can copy a table from one database to other using pg_dump tool.

Copy table from one database to another in PostgreSQL:

If table is empty then, run the below command from Linux.

pg_dump -t table_to_copy source_db | psql target_db

Continue reading How to Copy table from one database to another in PostgreSQL

Download and load PostgreSQL sample database

In this article, we will see download and load PostgreSQL sample database. PostgreSQL sample database is used for practice purpose only.
We can download the PostgreSQL sample database dvdrental from the github

Download and load PostgreSQL sample database:

1. Go to link https://github.com/robconery/dvdrental.

2. Create database with the name dvdrental from either Linux shell or psql shell.

From Linux shell

createdb dvdrental

From psql shell:

create database dvdrental;

3. From the Linux shell navigate to Downloads directory and execute below restore command.

pg_restore -d dvdrental dvdrental.tar

4. Then, connect to psql shell and run below command to verify PostgreSQL sample database loaded or not.

select * from pg_database where datname='dvdrental';

or

\l dvdrental