PostgreSQL 언어 데이터베이스에 node-postgres 연결

이 페이지에서는 PostgreSQL node-postgres 드라이버를 Spanner의 PostgreSQL 언어 데이터베이스에 연결하는 방법을 설명합니다. node-postgres는 PostgreSQL용 Node.js 드라이버입니다.

  1. PGAdapter가 PostgreSQL node-postgres 드라이버를 사용하여 연결하는 애플리케이션과 같은 머신에서 실행 중인지 확인합니다.

    자세한 내용은 PGAdapter 시작을 참조하세요.

  2. node-postgres 연결 속성에서 localhost5432를 데이터베이스 서버 호스트와 포트로 지정합니다.

    • 필요한 경우 PGAdapter가 기본 PostgreSQL 포트(5432)가 아닌 다른 포트에서 리슨하도록 구성되면 포트 번호를 지정합니다.
    • 원하는 경우 PGAdapter가 로컬 머신과 다른 호스트에서 실행 중이면 다른 호스트 이름을 지정합니다.
    const { Client } = require('pg');
    const client = new Client({
     host: 'localhost',
     port: 5432,
     database: 'my-database',
    });
    await client.connect();
    const res = await client.query("select 'Hello world!' as hello");
    console.log(res.rows[0].hello);
    await client.end();
    

다음 단계

  • PGAdapter에 대해 자세히 알아보세요.
  • PostgreSQL node-postgres 드라이버 연결 옵션에 대한 자세한 내용은 PGAdapter GitHub 저장소의 node-postgres 연결 옵션을 참조하세요.