Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostreSQL password #22

Open
Kanezal opened this issue Jul 5, 2024 · 4 comments
Open

PostreSQL password #22

Kanezal opened this issue Jul 5, 2024 · 4 comments

Comments

@Kanezal
Copy link

Kanezal commented Jul 5, 2024

setup this repo to my github codespace in devcontainer.json, in features. Also restart postgresql service to run postgres. So, what the postgres user password? How can I manage it?

@itsmechlark
Copy link
Owner

You should be able to access PostgreSQL directly but if still didn't work, please check the environment variables exported within your dev container here.

@c0d33ngr
Copy link

Hi @itsmechlark I had similar issue too. After setting up the postgresql service, I tried to login but got prompted for passoword. I tried vscode, codespace, and postgres but wasn't authenticated cause it was incorrect. I even add sudo at the front of psql -U postgres and still have to input password

Please do you mind telling me what I might not be doing well?

My devcontainer.json

{
  "features": {
    "ghcr.io/itsmechlark/features/postgresql:1.5.0": {}
  }

}

@c0d33ngr
Copy link

This is what I later did. I had to modified the pg_hba.conf file

.devcontainer/setup-postgres.sh

#!/usr/bin/env bash

# Get version number
major_version_number=$(psql --version | cut -d' ' -f3 | cut -d'.' -f1)

# Path to the pg_hba.conf file
PGHBA_CONF="/etc/postgresql/${major_version_number}/main/pg_hba.conf"

# Backup the original configuration file
cp $PGHBA_CONF ${PGHBA_CONF}.bak

# Modify the pg_hba.conf file to use 'trust' authentication
cat <<EOF > $PGHBA_CONF
# Database administrative login by Unix domain socket
local   all             all                                     trust
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust
EOF

# Restart PostgreSQL to apply changes
sudo service postgresql restart

echo "PostgreSQL configuration updated and service restarted."

.devcontainer/devcontainer.json

{
    "name": "PostgreSQL Playground",
    "features": {
      "ghcr.io/itsmechlark/features/postgresql:1.5.0": {}
    },
    "postCreateCommand": "sudo bash .devcontainer/setup-postgres.sh"  
}

@c0d33ngr
Copy link

After including an image in my devcontainer.json it seem to work fine

{
    "name": "PostgreSQL Dev Container Playground",
    "image": "mcr.microsoft.com/devcontainers/base:ubuntu",
    "features": {
      "ghcr.io/itsmechlark/features/postgresql:1": {
        "version": "latest"
      }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants