Capture long running method execution in Spring Boot using annotation
It is crucial to capture long running method execution in your application (whether it is an API or traditional mvc application). You should also …
In this post, we are going to find out how to backup postgresql database with pg_dump
utility.
pg_dump
utilityPostgreSQL provides the pg_dump
utility to simplify backing up a single database. This command
must be run as a user with read permission to the database we intend to back up.
3 types of backup files we have:
postgres
user:$ su - postgres
$ pg_dump your_db_name > backup_file_name.bak
$ pg_dump -U postgres -W -h localhost your_db_name > backup_file_name.bak
pg_dump
can be run from a client computer to back up data on a remote server. Use -h flag
to specify the IP address and -p to identify the port:$ pg_dump -h 13.34.232.23 -p 5432 your_db_name > backup_file_name.bak
# or
$ pg_dump -h 13.34.232.23 -p 5432 your_db_name > backup_file_name.sql
$ pg_dump -U postgres -W -h localhost your_db_name --schema-only > schemeonly.sql
$ pg_dump -U postgres -W -h localhost your_db_name --data-only > dataOnly.sql
$ pg_dump -U postgres -W -h localhost your_db_name -t your_table_name > tableBackup.sql
Note: When -t is specified, pg_dump makes no attempt to dump any other database objects that the selected table(s) might depend upon. Therefore, there is no guarantee that the results of a specific-table dump can be successfully restored by themselves into a clean database.
$ pg_dump -U postgres -W -h localhost local_Db --column-inserts --data- only > testAccount.sql
Dump data as INSERT commands (rather than COPY ). This will make restoration very slow
$ psql -U postgres -d your_db_name -h 1.2.3.4 -p 5432 -a -f /path/to/sql
## LOCAL DB EXAMPLE
$ psql -U postgres -d local_Db -h localhost -p 5432 -a -f /path/to/sql
-U
: username-d
: database name-a
: all echo-f
: path to SQL scriptIf you want to backup your database when yu are running inside containers, you may use the following command:
$ podman exec -it {your_docker_name} pg_dump -U postgres -W -h localhost your_db_name > backup_file_name.bak
DROP DATABASE IF EXISTS databasename;
CREATE DATABASE databasename
$ psql databasename < backup_file_name.bak
$ podman cp /path/to/sql {containerId}:/path/to/container/sql
$ psql -U postgres -W -h localhost {db_name} -p 5432 -a -f /path/to/container/sql
It is crucial to capture long running method execution in your application (whether it is an API or traditional mvc application). You should also …
Spring provides reliable shutdown of the application using feature called Graceful Shutdown. With Graceful shutdown feature we can close the …