fbpx

How to Take PostgreSQL Schema Backup

In some cases, we have to take PostgreSQL schema level backup. it’s like a logical backup where it just backup the schema objects like tables, indexes, and procedures. These backups are used in the condition where you need to restore just one schema backup, not the whole database. For daily backup, you can create a shell or bash script and schedule it using crontab or windows scheduler.

Script For Schema Backup

				
					#!/bin/bash
mv /tmp/db_list.log /tmp/db_list.log_old
psql -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;" > /tmp/db_list.log ; sed -i '/^$/d' /tmp/db_list.log
file=/tmp/db_list.log
#schema_name
#DB
date=$(date '+%Y-%m-%d')
bkp_path=/var/lib/pgsql

for DB in `cat $file`
do
echo "#################Starting the backup as on ${date} for ${DB}"
pg_dump -U postgres -v -n '*' -N 'pg_toast' -N 'information_schema' -N 'pg_catalog' $DB -Ft -f ${bkp_path}/${DB}_schema_bkp_${date}.tar > `${bkp_path}/${DB}_schema_bkp_${date}.log)`
echo "#################Backup Complited as on ${date} for ${DB}"
done

echo "listing files older than 15 Days"
find ${bkp_path} -name "*schem*.tar" -type f -mtime +1 > ${bkp_path}/old_file_list.log
find ${bkp_path} -name "*.log" -type f -mtime +1 > ${bkp_path}/old_file_list.log

echo "deleting backup/log file older than 15 Days"
find ${bkp_path} -name "*.tar" -type f -mtime +15 > ${bkp_path}/old_file_list.log -delete

				
			

In this script, we have excluded system schemas like ‘information_schema’ and many more. Please remove ‘-N and schema Name if you need a backup system schema.’ It will start including the schema backup in the tar file.

How to execute the Script ?

				
					chmod 777 backup_schema.sh
./backup_schema.sh

				
			

Read More...

How to connect PostgreSQL Database from PgAdmin

How to connect PostgreSQL Database from PgAdmin

In this article, we are going to see how we can connect to the PostgreSQL database from pgadmin. Its a GUI tool to manage and administer the PostgreSQL database. Using pgadmin, you can create and monitor PostgreSQL databases. You can get the pgadmin from offical website. Before you connect to any database from pgadmin you need valid hostname/AWS RDS endpoint and port. Also, you should have valid database credentials.

Steps to connect to PostgreSQL Database from PGAdmin

#1. Open the pgadmin utility #2. Go to servers right click add server #3. Enter the Host Name/IP or AWS RDS endpoint name. #4. Once you have added it successfully. Open and try to access the remote database. #5. Create a database for testing #6.  Give database name and click on ‘save‘. #7. Once created successfully it will ve visible under your connection name. #8. Create a table under the newly created database. #9. You can see the newly created table under the database ‘thedbadmin’. I hope you like this article. Please comment if you have any doubt. Like our Facebook page Read more AWS MySQL RDS Database Creation using AWS CLI How to Create MySQL Database with AWS RDS How to connect to AWS MySQL / MariaDB RDS or EC2 database from MySQL WorkBench How to Become Oracle apps DBA? What does DBA mean? 150 Oracle DBA Interview Questions Top 5 Future Technologies for Database Administrators (DBA) to learn in 2020 Top 5 Software Technology Trends in 2020 List

How to create AWS RDS PostgreSQL Database

How to create AWS rds PostgreSQL Database

 

In this article, we are going to talk about detailed steps to create an AWS Postgres database instance on AWS cloud. Amazon RDS has two options for PostgreSQL. The first one is the normal AWS Postgres RDS database and Another one is aurora PostgreSQL. AWS Postgres gives you a lot of performance gain and HA options comparing with the normal data center (DC) database. You can get AWS Postgres with few steps. I have mentioned all possible details in the post about AWS PostgreSQL. If you need any AWS PostgreSQL pricing details you can open the AWS calculator portal and can get details about estimated the cost.

In case if you have any question let me know my comments. Let’s start creating an AWS PostgreSQL RDS database instance.

 

 

1# Login to AWS console and Search for ‘RDS‘.

 

 

#2. Click on create on Database

 

 

#3. Select PostgreSQL .

 

 

 

#4.  Select the database template. In my case, I have selected ‘Free tier’ you can select ‘Production’ or ‘Dev/Test‘ according to your requirement. Production and Dev/test will not be free from the day one it will be chargeable.

 

 

#5. Give some meaningful database name and Master database username with password.

 

 

#6. I have selected the free database classes which come with the free tier.

 

 

#7. Based on your database storage needs to select the ‘Allocated space’.

 

 

#8. If your database is business-critical you can choose a Multi-Availability Zone for database high availability.

 

 

#9. Chose the default VPC. If you are configuring it for Production or development chose the appropriate VPC using the dropdown button.

 

 

[su_box title=”IMP Note for Additional connectivity configuration” box_color=”#fe2227″ title_color=”#101112″]In case if you like to access the database from your laptop/Desktop. Select the option ‘Publicly Accessible‘ to yes.[/su_box]

 

 

 

#10. Chose the option according to your application and the AWS ecosystem setup.

 

 

#11.  To enable  Cloudwatch logs or backup you can configure ‘Additional configuration‘.

 

 

#12. Click on ‘Create Database

 

 

#13.  It will take a few minutes to create database.

 

 

#14.  You can view the database credentials after clicking on ‘View credentials details‘ .

 

 

 

#15. You will see this message once your database is ready for action.

 

 

Please comment if you have any doubt. Like our Facebook page

 

Read more

AWS MySQL RDS Database Creation using AWS CLI
How to Create MySQL Database with AWS RDS
How to connect to AWS MySQL / MariaDB RDS or EC2 database from MySQL WorkBench

How to Become Oracle apps DBA?
What does DBA mean?
150 Oracle DBA Interview Questions
Top 5 Future Technologies for Database Administrators (DBA) to learn in 2020
Top 5 Software Technology Trends in 2020 List