fbpx

Migrate PostgreSQL From Cantos to Rocky Linux ?

Here are the steps you can follow to migrate a PostgreSQL database from CentOS to Rocky Linux:

  1. Install PostgreSQL on Rocky Linux: You will need to install PostgreSQL on your Rocky Linux system if it is not already installed. You can do this using the package manager for your Linux distribution.

  2. Stop the PostgreSQL service on CentOS: You will need to stop the PostgreSQL service on your CentOS system to ensure that the data is not modified during the migration process. You can do this using the systemctl command:

				
					systemctl stop postgresql

				
			
  1. Create a backup of the PostgreSQL data: You will need to create a backup of the PostgreSQL data on your CentOS system to ensure that you have a copy of the data that you can restore on Rocky Linux. You can use the pg_dump command to create a backup of the data:
				
					pg_dump -U username -W -Fc database_name > database_name.dump

				
			
  1. Transfer the backup file to Rocky Linux: You will need to transfer the backup file to your Rocky Linux system. You can use a tool like scp to copy the file from CentOS to Rocky Linux:
				
					scp database_name.dump username@rocky_linux_server:/path/to/destination

				
			
  1. Restore the backup on Rocky Linux: You can use the pg_restore command to restore the backup file on your Rocky Linux system:
				
					pg_restore -U username -W -d database_name database_name.dump

				
			
  1. Start the PostgreSQL service on Rocky Linux: Once the data has been restored, you can start the PostgreSQL service on your Rocky Linux system:
				
					systemctl start postgresql

				
			

I hope this helps! Let me know if you have any questions.

What is the Kubernetes Operator For Database?

A Kubernetes operator is a software extension to Kubernetes that helps manage complex applications or infrastructure. Operators use custom resources and controllers to automate tasks such as deploying, scaling, and backing up applications.

One of the main benefits of using Kubernetes operators is that they allow you to use the same API and tooling as Kubernetes to manage your applications, rather than having to use custom scripts or processes. This can make it easier to deploy and manage applications in a Kubernetes cluster.

Operators can be developed for a wide range of applications and infrastructure, including databases, messaging systems, and machine learning frameworks. They can be used to automate tasks such as creating and managing database clusters, deploying message brokers, and training and deploying machine learning models.

I hope this helps! Let me know if you have any questions.

There are several Kubernetes operators available for managing databases, including operators for MySQL, PostgreSQL, and MongoDB.

Here is an example of how you can use the MySQL Operator to deploy a MySQL cluster on Kubernetes:

  1. Install the MySQL Operator on your Kubernetes cluster. You can do this using the Kubernetes command-line tool kubectl.

  2. Create a configuration file for the MySQL cluster. This file should specify the number of MySQL instances you want to deploy, the size of the instances, and any other desired configuration options.

  3. Use kubectl to apply the configuration file and create the MySQL cluster. The MySQL Operator will handle the process of deploying the MySQL instances and setting up the cluster.

  4. Use kubectl to create a Kubernetes service for the MySQL cluster. This will allow other applications in the cluster to access the MySQL instances.

  5. Use the MySQL command-line client or another MySQL client to connect to the MySQL cluster and create databases and tables as needed.

I hope this gives you an idea of how you can use a Kubernetes operator to manage a database in a Kubernetes cluster. There are many other operators available for different types of databases, so you may want to research the specific operator that is best suited for your needs.

I hope this helps! Let me know if you have

How to ssh a Remote Linux Server?

To connect to a remote Linux server using Secure Shell (SSH), you will need to do the following:

  1. Install an SSH client on your local machine. If you are using a Unix-like operating system (e.g., Linux, macOS), you can use the built-in ssh command. If you are using Windows, you can use a program like PuTTY or MobaXterm.

  2. Determine the hostname or IP address of the remote server. This is the address that you will use to connect to the server. You can usually find the hostname or IP address in the server’s documentation or by contacting the server’s administrator.

  3. Open a terminal window on your local machine and enter the following command:

				
					ssh username@hostname

				
			

Replace username with your username on the remote server and hostname with the hostname or IP address of the server. For example:

				
					ssh john@server.example.com

				
			
  1. If this is the first time you have connected to the server, you may see a message asking you to confirm the authenticity of the server’s host key. Type yes and press Enter to continue.

  2. Enter your password when prompted. If you have entered the correct username and password, you should be logged into the remote server.

I hope this helps! Let me know if you have any questions.

Create AWS EC2 From AWS CLI with Public IP

This article will explain creating an ec2 instance with the AWS CLI option from the command line interface. AWS CLI is an easy and fast option for creating single or multiple ec2 instances. Using AWS CLI, you can automate total AWS infrastructure build and also, and you can query the existing infrastructure.

Create EC2

				
					aws ec2 run-instances --image-id  ami-090fa75af13c156b4 --count 1 --instance-type t2.micro --key-name awscli --security-group-ids sg-8f6dc695 --subnet-id subnet-88e3ea86
				
			

Create EC2 with Public IP

				
					aws ec2 run-instances --image-id  ami-090fa75af13c156b4 --count 5 --instance-type t2.micro --key-name awscli --security-group-ids sg-8f6dc695 --subnet-id subnet-88e3ea86 --associate-public-ip-address
				
			

List Runing EC2 instances

				
					aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicDNS:PublicDnsName,PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --output table
				
			

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 Fix Pg_ctl command not found

Sometimes after a fresh PostgreSQL install if we want to start or stop from PostgreSQL rather than controlling the PostgreSQL instance start and stop from the root. And when we run the pg_ctl from the command prompt as a PostgreSQL Linux user we see the error bash: pg_ctl: command not found… 

In this article, lets learn how to fix it

As PostgreSQL check your pg base directory 

 

And now add this PostgreSQL to the Linux path so that it’s always available. I would recommand to create a postgresql env. file so that it more easy to handle rather than messing with other systems runing on linux operating system.

				
					--Step 1 
-bash-4.2$ echo $PGDATA
/var/lib/pgsql/10/data

--Step 2
-bash-4.2$ echo "PATH=/usr/pgsql-10/bin:$PATH">>~/.postgre_10.profile

--Step 3
chmod 777 .postgre_10.profile

--Step 4 
. .postgre_10.profile

--Step 5
Check pg_ctl now

-bash-4.2$ pg_ctl --version
pg_ctl (PostgreSQL) 10.17
-bash-4.2$