How to View Log Files in YugabyteDB Using SQL

YugabyteDB is a distributed SQL database that offers full PostgreSQL compatibility — which means you can use familiar SQL functions to inspect logs directly from your SQL client (i.e. ysqlsh). Whether you’re troubleshooting or just monitoring server activity, checking logs is easy and doesn’t require shell access.

To list all files in the log directory, YugabyteDB supports:

				
					SELECT * FROM pg_ls_logdir();
				
			

Example:

				
					yugabyte=# SELECT * FROM pg_ls_logdir();
                               name                                |  size   |      modification
-------------------------------------------------------------------+---------+------------------------
 yb-tserver.cloud-server-0.root.log.INFO.20250501-200337.582979    | 1561006 | 2025-05-02 13:03:36+00
 yb-tserver.INFO                                                   | 1561006 | 2025-05-02 13:03:36+00
 yb-tserver.cloud-server-0.root.log.WARNING.20250501-200337.582979 |    3424 | 2025-05-02 12:22:20+00
 yb-tserver.WARNING                                                |    3424 | 2025-05-02 12:22:20+00
 initdb.log                                                        |       0 | 2025-05-01 20:03:37+00
 postgresql-2025-05-01_200337.log                                  |    9337 | 2025-05-01 23:45:56+00
 postgresql-2025-05-02_000000.log                                  |   10653 | 2025-05-02 12:51:35+00
(7 rows)
				
			

Looking at the output, I thought — wow, this is such an easy way to get the current PostgreSQL log file!

				
					yugabyte=# SELECT name current_pg_log FROM pg_ls_logdir() WHERE name ILIKE 'postgresql%' ORDER BY modification DESC LIMIT 1;
          current_pg_log
----------------------------------
 postgresql-2025-05-02_000000.log
(1 row)
				
			

Then I discovered there’s already a built-in function that returns the path of the currently active log file!

				
					SELECT pg_current_logfile();
				
			

Example:

				
					yugabyte=# SELECT pg_current_logfile() current_pg_log;
                           current_pg_log
---------------------------------------------------------------------
 /root/v1/data/yb-data/tserver/logs/postgresql-2025-05-02_000000.log
(1 row)
				
			

Now that I know where the current PostgreSQL log file is located, I can perform administrative tasks like listing any error records:

				
					yugabyte=# \! grep ERROR /root/v1/data/yb-data/tserver/logs/postgresql-2025-05-02_000000.log
2025-05-02 12:11:04.682 UTC [628761] ERROR:  invalid input syntax for integer: "a" at character 8
2025-05-02 12:12:01.714 UTC [628761] ERROR:  unrecognized configuration parameter "backtrace_functions"
2025-05-02 12:34:49.778 UTC [629334] ERROR:  function "*term*" does not exist at character 8
2025-05-02 12:51:32.179 UTC [630007] ERROR:  syntax error at or near "SELEC" at character 1
2025-05-02 12:51:35.093 UTC [630007] ERROR:  relation "pg_ls_logdir" does not exist at character 15
				
			

By using pg_current_logfile() and pg_ls_logdir(), you can introspect your YugabyteDB logs entirely via SQL — no SSH or manual file browsing required.

Notes:
  1. These functions are read-only and safe to use in production.
  2. You’ll need appropriate privileges to run them.

Have Fun!

My wife just kicked off her 2025 backyard garden — and I’m already mentally preparing. Last year, we had so many tomatoes and cucumbers, I started seeing Greek salads in my dreams and developed a mild fear of anything crunchy and green all winter long.