programing

postgresql에서 db에 대한 사용자를 생성하는 방법은 무엇입니까?

stoneblock 2023. 5. 29. 09:17

postgresql에서 db에 대한 사용자를 생성하는 방법은 무엇입니까?

Postgre를 설치했습니다.SQL 8.4 on my CentOS 서버 및 셸에서 root 사용자에게 연결되어 Postgre에 액세스SQL 셸.

Postgre에서 데이터베이스와 사용자를 만들었습니다.SQL.

PHP 스크립트에서 연결을 시도하는 동안 인증 실패로 표시됩니다.

새 사용자를 생성하고 특정 DB에 대한 사용 권한을 부여하는 방법은 무엇입니까?

CLI에서:

$ su - postgres 
$ psql template1
template1=# CREATE USER tester WITH PASSWORD 'test_password';
template1=# GRANT ALL PRIVILEGES ON DATABASE "test_database" to tester;
template1=# \q

PHP(localhost에서 테스트한 대로 예상대로 작동함):

  $connString = 'port=5432 dbname=test_database user=tester password=test_password';
  $connHandler = pg_connect($connString);
  echo 'Connected to '.pg_dbname($connHandler);

암호를 사용하여 사용자를 만듭니다.

http://www.postgresql.org/docs/current/static/sql-createuser.html

CREATE USER name [ [ WITH ] option [ ... ] ]

where option can be:

      SUPERUSER | NOSUPERUSER
    | CREATEDB | NOCREATEDB
    | CREATEROLE | NOCREATEROLE
    | CREATEUSER | NOCREATEUSER
    | INHERIT | NOINHERIT
    | LOGIN | NOLOGIN
    | REPLICATION | NOREPLICATION
    | CONNECTION LIMIT connlimit
    | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
    | VALID UNTIL 'timestamp'
    | IN ROLE role_name [, ...]
    | IN GROUP role_name [, ...]
    | ROLE role_name [, ...]
    | ADMIN role_name [, ...]
    | USER role_name [, ...]
    | SYSID uid

그런 다음 특정 데이터베이스에 대한 사용자 권한을 부여합니다.

http://www.postgresql.org/docs/current/static/sql-grant.html

예:

grant all privileges on database db_name to someuser;

언급URL : https://stackoverflow.com/questions/10861260/how-to-create-user-for-a-db-in-postgresql