skip to Main Content

I am trying to connect to my postgres db hosted on AWS RDS. But somehow I am getting the below mentioned error.
pg_hba.conf entry for host "103.215.537.148", user "dbmasteruser", database "postgres", no encryption

I am using postgres 15.2

I have tried checking on internet but I am not sure how to change the pg_hba.conf file on aws rds.

I tried connecting the db to ec2 and setting the inbound rules but nothing works.

Thanks for the help.

    import WebSocket from 'ws';
    import PGPubsub from 'pg-pubsub';
    import { db } from '../../config';

    const initializeWebSocket = async (server: any) => {
      const wss = new WebSocket.Server({ server });

      const connectionString =
        process.env.NODE_ENV === 'development'
          ? db.dev.DB_URL
          : db.production.DB_URL;
      console.log('_____', process.env.NODE_ENV, '______ws');

      const pgClient = new PGPubsub(
        'postgres://dbmasteruser:[email protected]:5432/postgres',
        { log: console.log },
      );


      const channel = 'users_insert';

      await pgClient.addChannel(channel, function (channelPayload) {
    
        console.log(channelPayload, 'channnel run is ther some insersion');
        wss.clients.forEach((client) => {
          if (client.readyState === WebSocket.OPEN) {
            client.send('Data in the database has changed');
          }
        });
      });

      const matchChannel = 'match_update';
      await pgClient.addChannel(matchChannel, function (channelPayload) {
        wss.clients.forEach((client) => {
          if (client.readyState === WebSocket.OPEN) {
            client.send('Data in the database has changed');
          }
        });
      });
      const res = await pgClient.publish(channel, { hello: 'world' });
  
    export default initializeWebSocket;

    import Logger from './core/Logger';
    import { port } from './config';
    import app from './app';
    import http from 'http';
    import WebSocket from './routes/webSocket/webSocketServer';
    console.log('hii server');

    const server = http.createServer(app);

    WebSocket(server);

    server
      .listen(port, () => {
        Logger.info(`server running on port : ${port}`);
      })
      .on('error', (e) => Logger.error(e));
        

2

Answers


  1. The error message suggests that there is a problem with the PostgreSQL connection setup. To solve a problem:

    Verify that the AWS RDS security group permits inbound traffic from the IP address of your application.

    Verify that your client is configured to use SSL if your RDS instance requires it.

    Check that your RDS endpoint, port, username, and password are accurate.

    Make sure your RDS instance contains the specified "postgres" database.

    Verify the RDS instance’s "dbmasteruser" permissions.

    Examine AWS RDS logs and keep an eye out for connection problems.

    Verify that PostgreSQL 15.2 is compatible with your client library.

    Check for firewall issues and network access.

    Verify environment variables once more for errors or wrong values.

    Hope it helps in solving your issue 🙂

    Login or Signup to reply.
  2. The only way I know of to get this error by itself is that the RDS instance is configured to force SSL with rds.force_ssl=1, and the client either doesn’t know how to use SSL, or has been configured not to. If this is the problem, either turn off force_ssl, or find a way to make the client cooperate.

    The other possibility is that the client first tried with SSL which failed for some other unshown reason, and then tried without SSL and got the shown error. Perhaps the client hides the first error message from you, or maybe you just overlooked it. In this case, the real error that needs to be solved is the other one which you haven’t shown us. If this is the case, the other error message can be found is the RDS log.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search