Sunday, 20 April 2025

all ec2 instance pg as remote access(EC2)

Is Blog se local se server per data create kar sakte hai.

1. On each EC2 instance, edit the PostgreSQL configuration file

1.1 sudo nano /etc/postgresql/<version>/main/postgresql.conf

# or for Amazon Linux

sudo nano /var/lib/pgsql/<version>/data/postgresql.conf

--

Update this line:

listen_addresses = '*' OR 
listen_addresses = '0.0.0.0'

---------------------------------------------------------------

2. Edit pg_hba.conf to Allow Remote Connections

On each instance, edit the pg_hba.conf file:

sudo nano /etc/postgresql/<version>/main/pg_hba.conf # or sudo nano /var/lib/pgsql/<version>/data/pg_hba.conf

Add the following line at the end (replace CIDR with the IP or IP range you want to allow):

host all all 0.0.0.0/0 md5

-----------------------------------------------

3. Open Port 5432 in EC2 Security Groups(This is most important)

Go to AWS EC2 Console → Security Groups, and for each EC2 instance:

  1. Find the associated Security Group.

  2. Click Inbound rulesEdit inbound rulesAdd rule:

    • Type: PostgreSQL

    • Protocol: TCP

    • Port Range: 5432

    • Source: Custom → <Your IP>/32 (or 0.0.0.0/0 for all IPs, use with caution)

----------------------------------------------------

4. Restart PostgreSQL

After making changes:

sudo systemctl restart postgresql # or sudo service postgresql restart
---------------------------------

5. Connect Remotely

Now you can connect from your local machine using a PostgreSQL client:

psql -h IP -U user_name -d database_name

ec2-ip: Server Ip address

username: Server pg username

6. Update Database.yml file

default: &default adapter: postgresql encoding: unicode pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: <%= ENV["DATABASE_USERNAME"] %> password: <%= ENV["DATABASE_PASSWORD"] %> database: <%= ENV["DATABASE_NAME"] %> host: <%= ENV["DATABASE_HOST"] %> development: <<: *default staging: <<: *default test: <<: *default production: <<: *default


Application.yml file

development:

  DATABASE_NAME: "database_name" # This is server database name

  DATABASE_HOST: "IP"

  DATABASE_USERNAME: "Server pg username"

  DATABASE_PASSWORD: "Server pg password"

Thursday, 10 April 2025

Sidekiq restart with new updation(like: update time, add new job(worker))

 1. ps aux | grep sidekiq

Get output: ubuntu    1111111  0.0  0.0   7008  2432 pts/0    S+   10:28   0:00 grep --color=auto sidekiq

2. kill -9 1111111

3. bundle exec sidekiq -d -L log/sidekiq.log

4. sudo service redis-server restart

5. sudo systemctl restart sidekiq