Docker postgresql'de bazı kullanıcı adlarının girişine izin vermiyor?

Öncelikle herkese iyi forumlar.

Docker üzerinde web uygulamam için bir test veritabanı oluşturmaya çalışıyorum ve bazı kullanıcı adlarında sorun yaşamazken bazı kullanıcı adlarını docker engelliyor.

Sorun olmayan docker komutu:

docker run -d --name c_pgd -p 5433:5432 -e POSTGRES_USER=tuncaydinler -e POSTGRES_PASSWORD=123456 -e POSTGRES_DB=deneme-db -v v_test:/var/lib/postgresql/data postgres

psql ile bağlanmaya çalıştığımda hiçbir sıkıntı olmuyor ve sorunsuz bağlanıyor:

psql -p 5433 -h localhost -U tuncaydinler -W -d deneme-db
psql (14.5 (Ubuntu 14.5-0ubuntu0.22.04.1), server 15.1 (Debian 15.1-1.pgdg110+1))
WARNING: psql major version 14, server major version 15.
         Some psql features might not work.
Type "help" for help.

deneme-db=# 

Ama ne zamanki kullanıcı adını root olarak değiştirsem:

docker run -d --name c_pgd -p 5433:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=123456 -e POSTGRES_DB=deneme-db -v v_test:/var/lib/postgresql/data postgres

Ve sonrasında psql ile bağlanmaya çalışsam:

psql -p 5433 -h localhost -U root -W -d deneme-db

Sadece kullanıcı adını değiştirmemle şöyle bir hata alıyorum:

psql: error: connection to server at "localhost" (127.0.0.1), port 5433 failed: FATAL:  password authentication failed for user "root"

Yardımcı olucak hocalarıma şimdiden teşekkür ederim.

EDIT: Aynı kodu docker-compose.yml içine yazıp çalıştırdığımda ise çalışıyor

version: "3.1"

services:
  s_pdb:
    container_name: c_pdb
    image: postgres
    ports:
      - "5433:5432"
    environment:
      - POSTGRES_PASSWORD=123456
      - PGDATA=/var/lib/postgresql/data/pgdata
      - POSTGRES_USER=root
      - POSTGRES_DB=deneme-db
psql -p 5433 -h localhost -U root -W -d deneme-db
psql (14.5 (Ubuntu 14.5-0ubuntu0.22.04.1), server 15.1 (Debian 15.1-1.pgdg110+1))
WARNING: psql major version 14, server major version 15.
         Some psql features might not work.
Type "help" for help.

deneme-db=# 

PostgreSQL’i root olarak calistirmak iyi bir fikir degil; “calismaz” diyenler bile var. Cozum baska bir kullanici ile calistirmak. root database kullanicisi ve database’leri yine yaratilabilir…

Tahminim compose ile yapildiginda postgres kullanicisiyla calistirilip root database kullanicisi yaratiliyor. Loglara bakmak lazim…

1 Beğeni

Hocam root ile oluşturulmamasını anladım ama elma,armut gibi saçma isimleride kabul etmiyor ?

↑↑↑

​​​​​​​​​​​​​​​​

1 Beğeni

Hocam önceki hatalı komutları tekrarladım ve loglara baktığımda şu çıktıyı alıyorum:

PostgreSQL Database directory appears to contain a database; Skipping initialization

2022-12-13 15:55:05.474 UTC [1] LOG:  starting PostgreSQL 15.1 (Debian 15.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-12-13 15:55:05.474 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2022-12-13 15:55:05.474 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2022-12-13 15:55:05.476 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-12-13 15:55:05.480 UTC [28] LOG:  database system was interrupted; last known up at 2022-12-13 15:53:31 UTC
2022-12-13 15:55:05.575 UTC [28] LOG:  database system was not properly shut down; automatic recovery in progress
2022-12-13 15:55:05.576 UTC [28] LOG:  redo starts at 0/195C328
2022-12-13 15:55:05.576 UTC [28] LOG:  invalid record length at 0/195C360: wanted 24, got 0
2022-12-13 15:55:05.576 UTC [28] LOG:  redo done at 0/195C328 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
2022-12-13 15:55:05.579 UTC [26] LOG:  checkpoint starting: end-of-recovery immediate wait
2022-12-13 15:55:05.584 UTC [26] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.002 s, sync=0.001 s, total=0.007 s; sync files=2, longest=0.001 s, average=0.001 s; distance=0 kB, estimate=0 kB
2022-12-13 15:55:05.589 UTC [1] LOG:  database system is ready to accept connections
2022-12-13 15:55:11.247 UTC [32] FATAL:  password authentication failed for user "root"
2022-12-13 15:55:11.247 UTC [32] DETAIL:  Role "root" does not exist.
	Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"

Soru root icin degil, elma ve armut icindi?

root kullanicisi yaratilmamis, Docker script’ine ve ciktisina bakmak lazim.

1 Beğeni

Hocam elma ve armut kullanıcı isimleri ile nerdeyse aynı hatayı veriyor:

PostgreSQL Database directory appears to contain a database; Skipping initialization

2022-12-13 16:04:29.805 UTC [1] LOG:  starting PostgreSQL 15.1 (Debian 15.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-12-13 16:04:29.805 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2022-12-13 16:04:29.805 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2022-12-13 16:04:29.807 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-12-13 16:04:29.811 UTC [28] LOG:  database system was interrupted; last known up at 2022-12-13 15:55:05 UTC
2022-12-13 16:04:29.901 UTC [28] LOG:  database system was not properly shut down; automatic recovery in progress
2022-12-13 16:04:29.902 UTC [28] LOG:  redo starts at 0/195C3D8
2022-12-13 16:04:29.902 UTC [28] LOG:  invalid record length at 0/195C410: wanted 24, got 0
2022-12-13 16:04:29.902 UTC [28] LOG:  redo done at 0/195C3D8 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
2022-12-13 16:04:29.904 UTC [26] LOG:  checkpoint starting: end-of-recovery immediate wait
2022-12-13 16:04:29.910 UTC [26] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.002 s, sync=0.001 s, total=0.007 s; sync files=2, longest=0.001 s, average=0.001 s; distance=0 kB, estimate=0 kB
2022-12-13 16:04:29.914 UTC [1] LOG:  database system is ready to accept connections
2022-12-13 16:04:40.501 UTC [32] FATAL:  password authentication failed for user "elma"
2022-12-13 16:04:40.501 UTC [32] DETAIL:  Role "elma" does not exist.
	Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
2022-12-13 16:04:46.990 UTC [33] FATAL:  password authentication failed for user "elma"
2022-12-13 16:04:46.990 UTC [33] DETAIL:  Role "elma" does not exist.
	Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
2022-12-13 16:04:54.846 UTC [34] FATAL:  password authentication failed for user "elma"
2022-12-13 16:04:54.846 UTC [34] DETAIL:  Role "elma" does not exist.
	Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
PostgreSQL Database directory appears to contain a database; Skipping initialization

2022-12-13 16:06:28.971 UTC [1] LOG:  starting PostgreSQL 15.1 (Debian 15.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-12-13 16:06:28.972 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2022-12-13 16:06:28.972 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2022-12-13 16:06:28.973 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-12-13 16:06:28.977 UTC [28] LOG:  database system was interrupted; last known up at 2022-12-13 16:04:29 UTC
2022-12-13 16:06:29.067 UTC [28] LOG:  database system was not properly shut down; automatic recovery in progress
2022-12-13 16:06:29.069 UTC [28] LOG:  redo starts at 0/195C488
2022-12-13 16:06:29.069 UTC [28] LOG:  invalid record length at 0/195C4C0: wanted 24, got 0
2022-12-13 16:06:29.069 UTC [28] LOG:  redo done at 0/195C488 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
2022-12-13 16:06:29.071 UTC [26] LOG:  checkpoint starting: end-of-recovery immediate wait
2022-12-13 16:06:29.077 UTC [26] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.002 s, sync=0.001 s, total=0.007 s; sync files=2, longest=0.001 s, average=0.001 s; distance=0 kB, estimate=0 kB
2022-12-13 16:06:29.081 UTC [1] LOG:  database system is ready to accept connections
2022-12-13 16:06:38.607 UTC [32] FATAL:  password authentication failed for user "armut"
2022-12-13 16:06:38.607 UTC [32] DETAIL:  Role "armut" does not exist.
	Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"

Kullanicilar yaratilmamis. PostgreSQL: Documentation: 15: 21.1. The pg_hba.conf File

1 Beğeni

Hocam sorunun çözümünü buldum yardımlarınız için çok sağolun.
Sorun volume yüzünden oluşuyormuş herhalde ilk oluşturduğumda hiçbir kullanıcı atamadığım için sonraki komutları çalıştırmamış.