PostgreSQL Kullanıcı Reset | Veritabanı Taşıma
- melihcelenk
- Site Admin
- Mesajlar: 217
- Kayıt: 05 Eki 2021, 03:23
PostgreSQL Kullanıcı Reset | Veritabanı Taşıma
# Step 1: Resetting the Password or Creating a New User
Find out the name of your PostgreSQL Docker container:
# Step 2: Importing the Remote Database
Option 1: Install the Matching PostgreSQL Client Version
Add the PostgreSQL apt repository
Here's how you can copy the dump.sql file from your host machine into the PostgreSQL container:
___________________________________________________________________________
Find out the name of your PostgreSQL Docker container:
Access the PostgreSQL container's bash shell:docker ps
Access the PostgreSQL command line:docker exec -it <container_name> bash
If you need to create a new user and database, run:psql -U postgres
Grant privileges to the user (if necessary):CREATE USER <username> WITH PASSWORD '<password>';
CREATE DATABASE <database_name> WITH OWNER <username>;
Exit the PostgreSQL command line:GRANT ALL PRIVILEGES ON DATABASE <database_name> TO <username>;
___________________________________________________________________________\q
# Step 2: Importing the Remote Database
Option 1: Install the Matching PostgreSQL Client Version
Add the PostgreSQL apt repository
Update package listsecho "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Install the matching client versionsudo apt-get update
____________________________________________________________________________sudo apt-get install postgresql-client-14
Here's how you can copy the dump.sql file from your host machine into the PostgreSQL container:
After you've copied the file into the container, you can then use the psql command inside the container to import the SQL dump:docker cp dump.sql <container_name>:/tmp/dump.sql
docker exec -it <container_name> psql -U <username> -d <database_name> -a -f /tmp/dump.sql
___________________________________________________________________________