Accessing PostgreSQL logs inside a container

Let's perform the following steps to get the logs from the application running inside a container:

  1. While you are in a shell, connect to the PostgreSQL database named postgresdb using the username testuser. You will see the PostgreSQL prompt, as follows:
$ psql --username testuser postgresdb
psql (12.1 (Debian 12.1-1.pgdg100+1))
Type "help" for help.
  1. While on the PostgreSQL prompt, use the following command to create a table and add some data to it:
CREATE TABLE test (
   id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
   a int NOT NULL,
   created_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO test (a) SELECT * FROM generate_series(-1, -1000, -1);
  1. Get the log's configuration details frompostgresql.conf. You will see that the logs are stored in the /var/log/postgresql directory:
$ cat /var/lib/postgresql/data/postgresql.conf |grep log
  1. List and access the logs in the /var/log/postgresql directory:
$ ls /var/log/postgresql
  1. Optionally, while you're inside the container, you can create a backup of our example postgresdb database in the tmp directory using the following command:
$ pg_dump --username testuser postgresdb > /tmp/backup.sql

With that, you have learned how to get shell access into a container and how to access the locally stored logs and files inside the container.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.77.158