CREST Practitioner Security Analyst (CPSA) Practice

Disable ads (and more) with a membership for a one time $2.99 payment

Master the CREST Practitioner Security Analyst Exam. Prepare with quizzes and comprehensive study guides that include tips and explanations. Excel in your certification journey!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Which of the following commands lists the databases in PostgreSQL?

  1. SELECT datname FROM pg_database

  2. SELECT database()

  3. SELECT * FROM information_schema.tables

  4. SHOW TABLES

The correct answer is: SELECT datname FROM pg_database

The command that effectively lists the databases in PostgreSQL is to execute a query against the `pg_database` system catalog, which stores information about all the databases within the PostgreSQL cluster. By using the statement that selects `datname`, you obtain the names of the databases available. This method is a direct approach for querying the catalog to retrieve the database names, thus providing an accurate listing. The other options do not correctly serve the purpose of listing databases in PostgreSQL. For instance, querying with `SELECT database()` is not a valid function in PostgreSQL; it's used in MySQL to return the current database being used. Another option, selecting from `information_schema.tables`, is intended to retrieve information about tables within a database rather than listing databases. Lastly, `SHOW TABLES` is a command applicable in MySQL for listing tables in the current database, but it is not used within PostgreSQL for databases specifically. Therefore, the selected command stands out as the appropriate choice for listing databases in PostgreSQL environments.