How to configure Prefect backend server to point to Postgres

2.1k views Asked by At

Having difficulties configuring Prefect to run locally. Installed via pip3, depends on docker(already installed) and docker-compose, installed, tested. works.
I already have a running Postgres server, I like to configure to use that one. But it seems like one is used in docker too ? Any help is appreciated.

When running:

prefect backend server 
prefect server start

nable to find image 'docker/compose:1.27.4' locally
1.27.4: Pulling from docker/compose (downloads en starts running docker)

Status: Downloaded newer image for docker/compose:1.27.4
WARNING: The PREFECT_SERVER_DB_CMD variable is not set. Defaulting to a blank string
WARNING: The DB_CONNECTION_URL variable is not set. Defaulting to a blank string
WARNING: The POSTGRES_DB variable is not set. Defaulting to a blank
WARNING: The POSTGRES_PASSWORD variable is not set. Defaulting to a blank string >
WARNING: The POSTGRES_USER variable is not set. Defaulting to a blank string.

3

There are 3 answers

0
Jesperrekuh On BEST ANSWER

The problem I encountered has to do with the way a subprocess is started in Python, Popen( docker-compose up, env=env ) The (current) environment variables are passed when running this command but in some way not available in the child task.

docker-compose up

I adjusted the server.py code and create an .env file on the fly. To test and docker-compose finds and uses it.

The real problem lies within the bash/sh terminal environment and thats where I need to take a closer look.

1
chriswhite On

If you reference the documentation for prefect server start you should find all the info you need:

prefect server start --help

... 
      --use-volume                Enable the use of a volume for the Postgres service
      --volume-path       TEXT    A path to use for the Postgres volume, defaults to
                                  '~/.prefect/pg_data'
0
chaitan94 On

Prefect now allows you to do this directly without running custom scripts on the fly.

You just need to specify the --external-postgres flag.

prefect server start --postgres-url postgres://<username>:<password>@hostname:<port>/<dbname>

OR you can also add it to .prefect/config.toml:

[server.database]
connection_url = "postgres://<username>:<password>@hostname:<port>/<dbname> "