EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL Show Databases
Secondary Sidebar
PostgreSQL Tutorial
  • Basic
    • What is PostgreSQL
    • PostgreSQL Features
    • How to Install PostgreSQL
    • PostgreSQL Versions
    • PostgreSQL Architecture
    • PostgreSQL GUI
    • Postgres Command-Line
    • PostgreSQL Variables
    • PostgreSQL Data Types
    • PostgreSQL NOT NULL
    • PostgreSQL Integer
    • PostgreSQL Boolean
    • PostgreSQL BIGINT
    • PostgreSQL NULLIF
    • PostgreSQL Administration
    • PostgreSQL Commands
    • PostgreSQL Operators
    • PostgreSQL IN Operator
    • Postgres like query
    • PostgreSQL encode
    • PostgreSQL Cheat Sheet
    • PostgreSQL List Databases
    • PostgreSQL Rename Database
  • Control Statement
    • PostgreSQL IF Statement
    • PostgreSQL if else
    • PostgreSQL CASE Statement
    • PostgreSQL LOOP
    • PostgreSQL For Loop
    • PostgreSQL While Loop
  • Joins
    • Joins in PostgreSQL
    • PostgreSQL Inner Join
    • PostgreSQL Outer Join
    • LEFT OUTER JOIN in PostgreSQL
    • PostgreSQL FULL OUTER JOIN
    • PostgreSQL LEFT JOIN
    • PostgreSQL Full Join
    • PostgreSQL Cross Join
    • PostgreSQL NATURAL JOIN
    • PostgreSQL UPDATE JOIN
  • Queries
    • PostgreSQL Queries
    • PostgreSQL INSERT INTO
    • PostgreSQL WHERE Clause
    • PostgreSQL WITH Clause
    • PostgreSQL ORDER BY
    • PostgreSQL ORDER BY Random
    • PostgreSQL ORDER BY DESC
    • PostgreSQL GROUP BY
    • PostgreSQL group_concat
    • PostgreSQL HAVING
    • PostgreSQL Recursive Query
  • Advanced
    • PostgreSQL Schema
    • Postgres List Schemas
    • PostgreSQL Drop Schema
    • PostgreSQL VARCHAR
    • Array in PostgreSQL
    • PostgreSQL DDL
    • PostgreSQL List Users
    • Postgres Default User
    • Postgres add user
    • PostgreSQL User Password
    • PostgreSQL log_statement
    • PostgreSQL repository
    • PostgreSQL shared_buffer
    • PostgreSQL String Functions
    • PostgreSQL Compare Strings
    • PostgreSQL Text Search
    • PostgreSQL TEXT
    • PostgreSQL String Array
    • PostgreSQL where in array
    • PostgreSQL Constraints
    • PostgreSQL UNIQUE Constraint
    • PostgreSQL CHECK Constraint
    • PostgreSQL INTERSECT
    • PostgreSQL Like
    • Cursors in PostgreSQL
    • PostgreSQL UNION ALL
    • Indexes in PostgreSQL
    • PostgreSQL Index Types
    • PostgreSQL REINDEX
    • PostgreSQL UNIQUE Index
    • PostgreSQL Clustered Index
    • PostgreSQL DROP INDEX
    • PostgreSQL DISTINCT
    • PostgreSQL FETCH
    • PostgreSQL RAISE EXCEPTION
    • PostgreSQL Auto Increment
    • Sequence in PostgreSQL
    • Wildcards in PostgreSQL
    • PostgreSQL Subquery
    • PostgreSQL Alias
    • PostgreSQL LIMIT
    • PostgreSQL Limit Offset
    • PostgreSQL LAG()
    • PostgreSQL Table
    • Postgres Show Tables
    • PostgreSQL Describe Table
    • PostgreSQL Lock Table
    • PostgreSQL ALTER TABLE
    • Postgres Rename Table
    • PostgreSQL List Tables
    • PostgreSQL TRUNCATE TABLE
    • PostgreSQL Table Partitioning
    • Postgres DROP Table
    • PostgreSQL Functions
    • PostgreSQL Math Functions
    • PostgreSQL Window Functions
    • Aggregate Functions in PostgreSQL
    • PostgreSQL Primary Key
    • Foreign Key in PostgreSQL
    • PostgreSQL Procedures
    • PostgreSQL Stored Procedures
    • PostgreSQL Views
    • PostgreSQL Materialized Views
    • Postgres Create View
    • PostgreSQL Triggers
    • PostgreSQL DROP TRIGGER
    • PostgreSQL Date Functions
    • PostgreSQL TO_DATE()
    • PostgreSQL datediff
    • PostgreSQL Timestamp
    • PostgreSQL CURRENT_TIMESTAMP()
    • PostgreSQL Notify
    • PostgreSQL LENGTH()
    • PostgreSQL blob
    • PostgreSQL Median
    • PostgreSQL kill query
    • PostgreSQL Formatter
    • PostgreSQL RANK()
    • PostgreSQL Select
    • PostgreSQL Average
    • PostgreSQL DATE_PART()
    • PostgreSQL EXECUTE
    • PostgreSQL COALESCE
    • PostgreSQL EXTRACT()
    • PostgreSQL Sort
    • PostgreSQL TO_CHAR
    • PostgreSQL Interval
    • PostgreSQL Number Types
    • PostgreSQL ROW_NUMBER
    • Alter Column in PostgreSQL
    • PostgreSQL Identity Column
    • PostgreSQL SPLIT_PART()
    • PostgreSQL CONCAT()
    • PostgreSQL replace
    • PostgreSQL TRIM()
    • PostgreSQL MAX
    • PostgreSQL DELETE
    • PostgreSQL Float
    • PostgreSQL OID
    • PostgreSQL log
    • PostgreSQL REGEXP_MATCHES()
    • PostgreSQL MD5 
    • PostgreSQL NOW()
    • PostgreSQL RANDOM
    • PostgreSQL round
    • PostgreSQL Trunc()
    • PostgreSQL TIME
    • PostgreSQL IS NULL
    • PostgreSQL CURRENT_TIME
    • PostgreSQL MOD()
    • Postgresql Count
    • PostgreSQL Datetime
    • PostgreSQL MIN()
    • PostgreSQL age()
    • PostgreSQL enum
    • PostgreSQL OR
    • PostgreSQL Wal
    • PostgreSQL NOT IN
    • PostgreSQL SET
    • PostgreSQL Current Date
    • PostgreSQL Compare Date
    • PostgreSQL SERIAL
    • PostgreSQL UUID
    • PostgreSQL Merge
    • PostgreSQL Database
    • PostgreSQL Clone Database
    • PostgreSQL Copy Database
    • PostgreSQL Show Databases
    • PostgreSQL Restore Database
    • PostgreSQL DROP DATABASE
    • PostgreSQL ALTER DATABASE
    • Postgres DROP Database
    • Postgres Dump Database
    • PostgreSQL OFFSET
    • PostgreSQL GRANT
    • PostgreSQL COMMIT
    • PostgreSQL ROLLUP
    • PostgreSQL JSON
    • EXPLAIN ANALYZE in PostgreSQL
    • PostgreSQL Temporary Table
    • PostgreSQL Show Tables
    • PostgreSQL cluster
    • PostgreSQL Replication
    • PostgreSQL Logical Replication
    • PostgreSQL flush privileges
    • PostgreSQL Tablespaces
    • CAST in PostgreSQL
    • PostgreSQL CTE
    • hstore in PostgreSQL
    • PostgreSQL Encryption
    • PostgreSQL DECODE()
    • PostgreSQL Vacuum
    • PostgreSQL EXCLUDE
    • Postgres Change Password
    • Postgres Delete Cascade
    • PostgreSQL EXCEPT
    • PostgreSQL Roles
    • PostgreSQL Link
    • PostgreSQL Partition
    • PostgreSQL column does not exist
    • PostgreSQL Log Queries
    • PostgreSQL escape single quote
    • PostgreSQL Query Optimization
    • PostgreSQL Character Varying
    • PostgreSQL Transaction
    • PostgreSQL Extensions
    • PostgreSQL Import CSV
    • PostgreSQL Client
    • PostgreSQL caching
    • PostgreSQL Incremental Backup
    • PostgreSQL JSON vs JSONNB
    • PostgreSQL JDBC Driver
    • PostgreSQL Interview Questions

PostgreSQL Show Databases

PostgreSQL Show Databases

Introduction to PostgreSQL Show Databases

The PostgreSQL provide show database command. The show database command is used to see how many databases are present on the server and this command works on command line tool psql as well as query tool in pgadmin4, this is the most common task of administrator. The PostgreSQL in which single progres(by default database) is able to store multiple databases and each database stored set of files. The PostgreSQL provides a different kind of feature to user like create a database, drop database and show database etc.

Psql provide the facility to connect the server and execute a different query against the server. MySQL uses show databases command to show database but show database statement does not work directly in PostgreSQL, it provides some different meta-commands to show database and different query statement.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax of PostgreSQL Show Databases

Given below are the syntax:

\l or \list

Explanation:

  • In the above syntax where \l is used to list all database lists from the server and the same database list, we can get by using another syntax \list.
  • The function of both syntaxes is the same. It is a Meta command we directly perform on the terminal.

select datname from pg_database;

Explanation:

  • In the above syntax where datname is used to show available databases from pg_database are by default catalog it is used to store all databases.

How does Show Databases Statement work in PostgreSQL?

Before going to see how to show database statement is work, we need some prerequisites as follows:

  • First, you must install PostgreSQL on your system.
  • Use below command to check PostgreSQL is working properly or not. If the status is active that means PostgreSQL is installed successfully.

Code:

service postgresql status

  • Also, install the psql command-line PostgreSQL interface.
  • Multiple databases are available to users but it can be accessed when the connection is established between client and server.
  • Users perform different operations on databases with the help of show database commands by using like operators.

Show Database Statement as follows:

Code:

\l

This is Meta Command it is used to the listing of the database for PostgreSQL database.

Output:

PostgreSQL Show Databases 1

In the above screen snapshot, it lists all databases that are present on the server.

Code:

\list

This is also Meta Command, the function of \List is the same as \l.

Output:

PostgreSQL Show Databases 2

We create database by using following statement.

Code:

create  database  test;

Output:

PostgreSQL Show Databases 3

Then use \list Meta Command to see the database.

Code:

\list

Output:

PostgreSQL Show Databases 4

We can also show the database by using PostgreSQL query:

Example #1

First, we create a database with name demo.

Code:

create  database   demo;

Output:

PostgreSQL Show Databases 5

After we perform show database query as follow:

Code:

select    datname     from    pg_database;

Output:

PostgreSQL Show Databases 6

In the above snapshot, the created database demo shows in the fifth number.

Another example of a database is before creations of a new database we need to see how many databases may be available on the server that time we use the following query.

Code:

select    datname    from    pg_database;

Output:

PostgreSQL Show Databases 7

The above snapshot shows 3 by default databases like Postgres, template1, template0 and college is a user-created database.

Example #2

PostgreSQl provide the facility to create database with owner.

Code:

create  database  demo1  with  owner =pg_monitor;

In the above statement, we use a create a statement to create a database and we created a demo1 database with owner pg_monitor.

Output:

PostgreSQL Show Databases 8

Now see the database column demo1 is created.

Code:

select   datname  from   pg_database;

Output:

column demo1 is created

Example #3

In PostgreSQL by default database is Postgres but different users created a number of databases and we need to only see those names start d characters. PostgreSQL provides such a facility.

Code:

Select   datname      from    pg_database
where      datname     like 'd%';

Explanation:

  • In the above statement, we find out all databases whose name start with d using the like operator.

Output:

PostgreSQL Show Databases 10

Let’s see another situation: suppose we need a database that name ends with e.

Code:

select      datname       from   pg_database
where      datname     like '%e';

In the above statement where datname is database name, pg_database by default database of PostgreSQL here we use like operator to show database.

Output:

ends with e

Example #4

Suppose in our server number of database is present and we don’t want to see those database names start with t.

Code:

select   datname     from      pg_database
where   datname   not like 't%';

Explanation:

  • In the above statement, we use not like operators to get the desired result.

Output:

Before the execution of the above statement result as shown in the snapshot.

Before the execution

After Execution of the above statement result as shown in the snapshot.

After Execution

In the above snapshot, it discards the database name whose start with t character.

Conclusion

From the above article, we saw show database Meta command as well as we implement show database by using query statements. In a query statement, we use like operator to perform a smooth search on the database that means as per our requirement we perform the show database. Finally, it is a time-saving process in PostgreSQL.

Recommended Articles

This is a guide to PostgreSQL Show Databases. Here we discuss the introduction and how does show databases statement work in PostgreSQL? You may also have a look at the following articles to learn more –

  1. PostgreSQL MAX
  2. PostgreSQL RAISE EXCEPTION
  3. PostgreSQL Logical Replication
  4. PostgreSQL Formatter
Popular Course in this category
PostgreSQL Course (2 Courses, 1 Project)
  2 Online Courses |  1 Hands-on Project |  7+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more