-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6068 from EnterpriseDB/release-2024-09-18a
Release 2024-09-18a
- Loading branch information
Showing
71 changed files
with
1,220 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
--- | ||
title: Installing PostgreSQL in a Docker container on your local machine | ||
navTitle: Docker | ||
description: Learn how to install PostgreSQL in a Docker container on your local machine for development purposes. | ||
deepToC: true | ||
--- | ||
|
||
## Prerequisites | ||
|
||
* Docker-compatible OS (macOS, Windows, Linux) | ||
|
||
Using Docker for your local PostgreSQL development environment streamlines setup, ensures consistency, and simplifies management. It provides a flexible, isolated, and portable solution that can adapt to various development needs and workflows. | ||
|
||
## Preparing Docker | ||
|
||
### Install Docker: | ||
|
||
Make sure Docker is installed on your machine or download and install it from [Docker’s official website](https://www.docker.com/products/docker-desktop/). | ||
|
||
* macOS: Download and install Docker Desktop from Docker’s official website. | ||
* Windows: Download and install Docker Desktop from Docker’s official website. Ensure WSL 2 is enabled if using Windows 10 or later. | ||
* Linux: Install Docker using your distribution’s package manager. For example, on Ubuntu: | ||
|
||
``` | ||
sudo apt update | ||
sudo apt install docker.io | ||
sudo systemctl start docker | ||
sudo systemctl enable docker | ||
sudo usermod -ag docker $USER | ||
newgrp docker | ||
``` | ||
|
||
|
||
### Pull the PostgreSQL Docker image: | ||
|
||
Open a terminal or command prompt and run the following command to pull the latest PostgreSQL image from Docker Hub: | ||
|
||
``` | ||
docker pull postgres | ||
``` | ||
|
||
## Running the PostgreSQL container | ||
|
||
Run a new container with the PostgreSQL image using the following command: | ||
|
||
``` | ||
docker run --name my_postgres -d postgres -e POSTGRES_PASSWORD=mysecretpassword -v my_pgdata:/var/lib/postgresql/data -p 5432:5432 | ||
``` | ||
|
||
#### `--name my_postgres` | ||
|
||
The `--name` flag tells docker to creates a new container named `my_postgres`. | ||
|
||
#### `-d` | ||
|
||
The `-d` flag tells Docker to run the container in detached mode. This means the container runs in the background and does not block the terminal. | ||
|
||
#### `postgres` | ||
|
||
This is the name of the image to run. Docker uses this name to pull the image from Docker Hub if it is not already present on the local machine. Note that if we had not pulled it, this command would automatically pull the PostgreSQL image. | ||
|
||
#### `-e POSTGRES_PASSWORD=mysecretpassword` | ||
|
||
The `-e` flag sets an environment variable `POSTGRES_PASSWORD` to `mysecretpassword`. This is used the password for the default `postgres` user. You should use a different password. | ||
|
||
#### `-v my_pgdata:/var/lib/postgresql/data` | ||
Docker uses volumes to persist data in Docker containers. This flag mounts a volume named `my_pgdata` to persist data. | ||
The data in this case is whatever Postgres writes to the `/var/lib/postgresql/data` directory within the container. | ||
These writes are persisted outside the container in a docker volume; the command `docker volume inspect my_pgdata` will show you information about that volume. | ||
|
||
#### `-p 5432:5432` | ||
|
||
The `-p` flag maps the container’s port 5432 to the host machine’s port 5432. Port 5432 is Postgres's default port for communications. By using this flag, it allows you to access the PostgreSQL database from your host machine. | ||
|
||
## Verifying the container is running | ||
|
||
To verify that the container is running, use the following command: | ||
|
||
``` | ||
docker ps | ||
``` | ||
|
||
This command lists all running containers. You should see the `my_postgres` container listed. | ||
|
||
You now have a persistent, locally accessible Postgres database running in a Docker container. | ||
You can now start using it. | ||
|
||
## Access PostgreSQL with a client | ||
|
||
To access the PostgreSQL database, without any additional tools, you can use the following command to open a PostgreSQL prompt: | ||
|
||
``` | ||
docker exec \-it my\_postgres psql \-U postgres | ||
``` | ||
|
||
This logs into the Docker container and runs the `psql` command as the `postgres` user from there. | ||
|
||
The `psql` command is a powerful tool for interacting with PostgreSQL databases. You should install it on your local machine to interact with the PostgreSQL database running in the Docker container. | ||
|
||
### macOS | ||
|
||
You can install the PostgreSQL client using Homebrew: | ||
|
||
``` | ||
brew install libpq | ||
``` | ||
|
||
### Windows | ||
|
||
Download the PostgreSQL client from the [official website](https://www.enterprisedb.com/downloads/postgres-postgresql-downloads). | ||
|
||
### Linux | ||
|
||
Use your distribution’s package manager to install the PostgreSQL client. For example, on Ubuntu: | ||
|
||
``` | ||
sudo apt-get install postgresql-client | ||
``` | ||
|
||
## Connecting other apps | ||
|
||
You can also connect other applications to the PostgreSQL database running in the Docker container. You need to provide the following connection details: | ||
|
||
* Host: `localhost` | ||
* Port: `5432` | ||
* Username: `postgres` | ||
* Password: (whatever you set it to) | ||
* Database: `postgres` | ||
|
||
Or use the connection string: | ||
|
||
``` | ||
postgresql://postgres:mysecretpassword@localhost:5432/postgres | ||
``` | ||
|
||
## Verifying data persistence | ||
|
||
1. Create a table and insert data. | ||
Access the PostgreSQL instance and run the following SQL commands to create a table with columns and insert some data: | ||
|
||
```sql | ||
CREATE TABLE employees ( | ||
id SERIAL PRIMARY KEY, | ||
first_name VARCHAR(50), | ||
last_name VARCHAR(50), | ||
email VARCHAR(100), | ||
hire_date DATE | ||
); | ||
INSERT INTO employees (first_name, last_name, email, hire_date) VALUES | ||
('John', 'Doe','[email protected]', '2020-01-15'), | ||
('Jane', 'Smith', '[email protected]', '2019-03-22'); | ||
``` | ||
|
||
2. Stop and completely remove the container. | ||
``` | ||
docker stop my_postgres | ||
docker rm my_postgres | ||
``` | ||
|
||
3. Recreate the container with the same volume. | ||
|
||
``` | ||
docker run --name my_postgres -d postgres -e POSTGRES_PASSWORD=mysecretpassword -v my_pgdata:/var/lib/postgresql/data -p 5432:5432 | ||
``` | ||
|
||
4. Verify Data Persistence. | ||
Access the PostgreSQL instance and check if the data still exists: | ||
|
||
```sql | ||
SELECT * FROM employees | ||
``` | ||
|
||
If everything worked as expected, you should see the employee table with the data previously loaded still present. | ||
|
||
|
||
## Stopping and removing the container | ||
|
||
To stop and remove the container, use the following commands: | ||
|
||
``` | ||
docker stop my_postgres | ||
docker rm my_postgres | ||
``` | ||
## Deleting the volume | ||
To remove the volume containing the database, use the following command (after stopping and removing the container): | ||
``` | ||
docker volume rm my_pgdata | ||
``` | ||
## Conclusion | ||
By following these steps, you have set up a robust local development environment for PostgreSQL using Docker. This setup ensures data persistence and provides a flexible, isolated, and consistent environment for all of your development needs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: Deploying Postgres for developers | ||
navTitle: Deploying for developers | ||
description: How to deploy Postgres for developers. | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
title: The EDB Postgres AI Developer Guides | ||
navTitle: Developer Guides | ||
description: The EDB Postgres AI Developer Guides provide information on how to use the EDB Postgres AI platform to build and develop Postgres and AI applications. | ||
deepToC: true | ||
directoryDefaults: | ||
iconName: "CodeWriting" | ||
indexCards: simple | ||
prevNext: true | ||
navigation: | ||
- deploy | ||
- working | ||
--- | ||
|
||
The EDB Postgres AI Developer Guides are all about providing you, the developer, with the information you need to accelerate your development efforts using the EDB Postgres AI platform. The guides cover a wide range of topics, from setting up your development environment to deploying Postgres and AI applications. | ||
|
||
## Deploying Postgres Locally for developers | ||
|
||
* [Deploying Postgres Using Docker Locally](deploy/docker) | ||
|
||
## Working with Postgres | ||
|
||
* [PSQL for busy developers](working/psql-for-busy-developers) | ||
|
||
<!-- ## Developing Postgres Applications | ||
|
||
* [Developing Postgres Applications with Python](developing/developing-postgres-applications-with-python) | ||
--> | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: Working with Postgres tools - guides for developers | ||
navTitle: Working with tools | ||
description: How to work with a range of Postgres tools, with a focus on developers and debugging. | ||
--- | ||
|
83 changes: 83 additions & 0 deletions
83
advocacy_docs/dev-guides/working/psql-for-busy-developers.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
title: PSQL for busy developers | ||
navTitle: PSQL for developers | ||
description: How to use PSQL for common developer tasks | ||
--- | ||
|
||
The PSQL command line tool is essential in a developer's toolkit as it provides full command-line access to PostgreSQL databases. | ||
|
||
## Getting psql installed | ||
|
||
The `psql` command is a powerful tool for interacting with PostgreSQL databases. You should install it on your local machine to interact with the PostgreSQL database. Unless you've just installed Postgres natively on your machine, you'll need to install the `psql` client. | ||
|
||
### macOS: | ||
|
||
You can install the PostgreSQL client using [Homebrew](brew.sh): | ||
|
||
``` | ||
brew install libpq | ||
``` | ||
|
||
### Windows: | ||
|
||
Download the PostgreSQL client from the [official website](https://www.enterprisedb.com/downloads/postgres-postgresql-downloads). | ||
|
||
### Linux: | ||
|
||
Use your distribution’s package manager to install the PostgreSQL client. For example, on Ubuntu: | ||
|
||
``` | ||
sudo apt-get install postgresql-client | ||
``` | ||
|
||
## Connecting to a database | ||
|
||
### Connection strings | ||
|
||
The `psql` client can use a connection string to connect to a database. The connection string is a single string that contains all the information needed to connect to a database. | ||
|
||
!!! tip | ||
Always wrap your connection string in single quotes to avoid the shell interpreting any special characters. | ||
!!! | ||
|
||
### PGPASSWORD environment variable | ||
|
||
Best practice is to not have your password in your connection string or in your command history. Instead, you can use the `PGPASSWORD` environment variable to store your Postgres password. This is simple, but not very secure because some Unix systems allow other users to see the environment variables of other users. | ||
|
||
### .pgpass file | ||
|
||
Creating a .pgpass file is a more secure way to store your password. The .pgpass file is a plain text file that contains the connection information for your databases. The file should be stored in your home directory and should be readable only by you. The file should have the following format: | ||
|
||
``` | ||
hostname:port:database:username:password | ||
``` | ||
|
||
Hostname, port, database and username can all be set to wildcards to match any value. For example, `*:*:*:postgres:password` would match any database on any host for the user `postgres`. | ||
|
||
Read more about the .pgpass file in the [Postgres documentation](https://www.postgresql.org/docs/current/libpq-pgpass.html). | ||
|
||
## The PSQL command line | ||
|
||
You can enter SQL commands directly into the PSQL command line. Be sure to end each command with a semicolon, otherwise PSQL doesn't execute the command. | ||
|
||
You can use tab-completion in many situations to help you complete commands and table names. Pressing tab at the start of a line will show you a list of available SQL commands. | ||
|
||
PSQL also has a number of built-in commands that can help you manage your databases and tables. | ||
|
||
|
||
| Command | Description | | ||
|-----------------|----------------------------------------------------------| | ||
| `\l` | List all databases | | ||
| `\c` | Connect to a database | | ||
| `\d` | List tables, sequences and views in the current database | | ||
| `\d table_name` | Describe a table | | ||
| `\watch seconds` | Re-run a query every `seconds` | | ||
| `\q` | Quit PSQL | | ||
|
||
`\d` is a very useful command that shows a range of different information when followed by another character. Think of it as `d` for display. For example, `\dt` shows all the tables in the current database, `\dv` shows all the views, and `\ds` shows all the sequences. | ||
|
||
`\watch` is useful when you want to repeat running a query at regular intervals. For example, you could use `\watch 5` to run a query every 5 seconds. The query that will be re-run is the last query you entered. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...docs/edb-postgres-ai/cloud-service/managing_your_cluster/backup_and_restore.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...s/edb-postgres-ai/cloud-service/managing_your_cluster/deleting_your_cluster.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...y_docs/edb-postgres-ai/cloud-service/managing_your_cluster/managing_cluster.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...cy_docs/edb-postgres-ai/cloud-service/managing_your_cluster/migration/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ostgres-ai/cloud-service/managing_your_cluster/modifying_your_cluster/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...cs/edb-postgres-ai/cloud-service/managing_your_cluster/periodic_maintenance.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../edb-postgres-ai/cloud-service/managing_your_cluster/upgrading_your_cluster.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
c8ddb4f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://edb-docs-staging.netlify.app as production
🚀 Deployed on https://66eaf850d1132045ea8e05cc--edb-docs-staging.netlify.app
c8ddb4f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://edb-docs.netlify.app as production
🚀 Deployed on https://66eaf9b6c5371d4a824ee23c--edb-docs.netlify.app