DeveloperBreeze

How To view tables and the number of records in each table in a PostgreSQL database,

To view tables and the number of records in each table in a PostgreSQL database, you can use the following methods.


Method 1: Using SQL Queries in psql

  1. Connect to PostgreSQL:

Start by connecting to your database using:

   psql -U your_username -d your_database_name
  1. List Tables:

To list all tables in the current schema, use:

   \dt
  1. View Record Counts for Each Table:

Run the following SQL query to see the list of tables along with their row counts:

   SELECT relname AS table_name,
          n_live_tup AS row_count
   FROM pg_stat_user_tables
   ORDER BY table_name;

This query fetches the table names and live row estimates from PostgreSQL’s statistics catalog, pg_stat_user_tables.


Method 2: Using a Database Client (e.g., pgAdmin)

  1. Open pgAdmin and connect to your PostgreSQL server.
  2. Navigate to the Database: In the left sidebar, expand your database and go to Schemas > Tables.
  3. View Table and Row Count:
  • Right-click on each table, select View/Edit Data > All Rows to see the records.
  • Or, run the above SQL query in the Query Tool to see all tables with row counts.

These methods will help you view tables and get a record count for each in your PostgreSQL database.

Related Posts

More content you might like

Tutorial

How to Stop SSH From Timing Out

If your SSH session closes after a minute of inactivity, it’s usually caused by idle timeouts. You can fix this with keep-alive settings on both the server and client.

Edit the SSH daemon config:

Aug 21, 2025
Read More
Tutorial

Protect Your Forms Like a Pro: Anti-Spam Techniques That Actually Work

const duration = Date.now() - formStartTime;
if (duration < 3000) {
  return res.status(403).send("Too fast, bot?");
}

Yes, reCAPTCHA is still useful—especially v3, which assigns a score based on user behavior.

Apr 04, 2025
Read More
Tutorial

How to install PostgreSQL

   sudo apt install postgresql postgresql-contrib

PostgreSQL starts automatically; to check the status:

Nov 06, 2024
Read More
Tutorial

How to view tables on a PostgreSQL database hosted on Heroku

   \q

Run the following command to get your database URL:

Nov 06, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!