Shubham
07/08/2026, 7:16 PMMarvin
07/08/2026, 7:16 PMMarvin
07/08/2026, 7:19 PMini
my prefect service file Unit]
Description=Prefect Server
It must start with:
ini
[Unit]
Description=Prefect Server
If [Unit] is wrong or missing, systemd may not be reading the unit as expected.
2. This line is wrong because of the angle brackets around the whole value
ini
Environment="PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
It should be:
ini
Environment="PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
Do not wrap the URL in < >. Those become literal characters in the value, which will break parsing.
3. prefect config view is showing your CLI profile, not necessarily the systemd service environment
So this output:
bash
prefect config view
only tells you what your shell session sees. It does not prove the systemd service got the same env vars.
4. If prefect version shows Database: sqlite, your current shell does not have the Postgres DB setting applied
That means either:
- the env var is only in systemd and not in your shell
- or the service file is not being loaded correctly
- or the DB URL value is invalid
Your current prefect version output strongly suggests Prefect is falling back to SQLite.
Recommended fixed unit file
ini
[Unit]
Description=Prefect Server
After=network-online.target postgresql.service
Wants=network-online.target
[Service]
Type=simple
User=root
WorkingDirectory=/home/prefect
Environment="PREFECT_HOME=/home/prefect/.prefect"
Environment="PREFECT_SERVER_API_HOST=192.168.29.151"
Environment="PREFECT_SERVER_API_PORT=4200"
Environment="PREFECT_SERVER_API_KEEPALIVE_TIMEOUT=60"
Environment="PREFECT_SERVER_LOGGING_LEVEL=DEBUG"
Environment="PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
Environment="PREFECT_SERVER_API_AUTH_STRING=astra:Network@5714"
ExecStart=/home/prefect/.venv/bin/prefect server start --host 0.0.0.0 --port 4200 --keep-alive-timeout 60
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
Then reload and restart systemd
bash
sudo systemctl daemon-reload
sudo systemctl restart prefect-server
sudo systemctl status prefect-server
Check what environment systemd actually loaded
bash
sudo systemctl show prefect-server --property=Environment
You should see PREFECT_API_DATABASE_CONNECTION_URL=postgresql+asyncpg://...
Check service logs
bash
journalctl -u prefect-server -n 100 --no-pager
If the DB URL is bad, Prefect usually logs startup/database errors there.
Test the DB setting directly in your shell
This is the fastest way to confirm the setting itself works:
bash
export PREFECT_API_DATABASE_CONNECTION_URL="<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
prefect version
If that is correct, prefect version should stop showing SQLite.
Important note about auth vars
For a server process, PREFECT_SERVER_API_AUTH_STRING is the right server-side setting.
For CLI/client access, PREFECT_API_AUTH_STRING is the client-side setting.
So if you want your shell CLI to authenticate too, you may also need:
bash
export PREFECT_API_AUTH_STRING="astra:Network@5714"
Docs
- Settings and profiles
- Self-hosted Prefect
- Security settings
If you want, I can help you with a step-by-step verification checklist for this exact server so we can pinpoint whether the issue is:
- bad unit syntax
- bad env var value
- systemd not reloading
- or Postgres connection failure.Shubham
07/08/2026, 7:36 PMMarvin
07/08/2026, 7:36 PMMarvin
07/08/2026, 7:36 PMprefect version is checking your current shell environment/profile, not proving what the systemd service is using.
So if you run:
bash
prefect version
and it shows SQLite, that only means your shell session is still configured for SQLite.
Let’s stop guessing and test this in the shortest possible way.
Run these exact commands in your shell:
bash
export PREFECT_API_DATABASE_CONNECTION_URL="<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
prefect version
If it still says SQLite after that, then one of these is true:
- the variable name is not being honored in your environment
- the URL is invalid
- Prefect is ignoring it because another setting is overriding it
- or the command is not reading what we expect
Then try this too:
bash
export PREFECT_SERVER_DATABASE_CONNECTION_URL="<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
prefect version
If both still show SQLite, then don’t focus on systemd yet. The issue is reproducible directly in the shell.
Next, inspect the active config value directly:
bash
prefect config view --show-sources
Look specifically for anything related to database connection settings.
Also run:
bash
env | grep PREFECT
That will show exactly what Prefect-related env vars are present in your current shell.
Most likely problem in your case
Your output shows:
bash
Profile: server
Server type: server
Server:
Database: sqlite
That suggests the active profile is still configured for local SQLite, and your shell does not actually have the DB env var set.
Also, your service file used this earlier:
ini
Environment="PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://...>"
Those < > absolutely make the value wrong. If systemd loaded that, Prefect would not parse it as a valid connection URL.
What I want you to run now
bash
export PREFECT_API_DATABASE_CONNECTION_URL="<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
env | grep PREFECT_API_DATABASE_CONNECTION_URL
prefect config view --show-sources
prefect version
And for systemd:
bash
sudo systemctl daemon-reload
sudo systemctl restart prefect-server
sudo systemctl show prefect-server --property=Environment
journalctl -u prefect-server -n 100 --no-pager
Important reality check
If the server process is using Postgres correctly, prefect version in your shell can still show SQLite unless you also exported the same DB env var in that shell.
So the better question is:
Is the running server actually using SQLite or Postgres?
To verify that, check the server logs after restart. If it connects to Postgres, logs will show DB migration/connection behavior. If it falls back or fails, the journal will show why.
If you want, send me the output of just these 3 commands:
bash
env | grep PREFECT
prefect config view --show-sources
sudo systemctl show prefect-server --property=Environment
and I’ll tell you exactly where it’s going wrong.Shubham
07/08/2026, 7:39 PMMarvin
07/08/2026, 7:39 PMMarvin
07/08/2026, 7:39 PMbash
Server:
Database: postgresql
PostgreSQL version: 16.14
So the original problem is resolved.
What changed?
Most likely one of these fixed it:
- removing the invalid < > around the DB URL
- exporting the correct environment variable
- reloading/restarting systemd
- correcting the service file formatting
What this means
Your Prefect server is no longer using SQLite fallback. It is now connected to Postgres as intended.
Recommended next checks
bash
sudo systemctl status prefect-server
journalctl -u prefect-server -n 50 --no-pager
And if you want to verify the UI/API is healthy:
bash
curl <http://192.168.29.151:4200/api/health>
You should get a healthy response.
Suggestion
Now that it works, save the final clean unit file and avoid editing it further unless necessary.
If you want, I can help you with a production-ready Prefect systemd service file next, including:
- running as a non-root user
- auto-restart
- environment file usage
- safer secrets handling
- log tuningShubham
07/08/2026, 7:47 PMMarvin
07/08/2026, 7:47 PMMarvin
07/08/2026, 7:47 PMini
Environment="PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
Those < > should not be there.
So right now:
- your shell is using a correct env var, which is why prefect version shows PostgreSQL
- but systemd service is still configured with an invalid value
That means the running service may fail on restart or may not be using the config you think it is.
Fix this exact line
Change:
ini
Environment="PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
To:
ini
Environment="PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
Then reload and restart:
bash
sudo systemctl daemon-reload
sudo systemctl restart prefect-server
sudo systemctl status prefect-server
Then verify what systemd actually loaded:
bash
sudo systemctl show prefect-server --property=Environment
Then check logs:
bash
journalctl -u prefect-server -n 100 --no-pager
Important distinction
Your prefect config view says:
bash
PREFECT_API_DATABASE_CONNECTION_URL='****' (from env)
That only confirms your current shell has the env var.
It does not confirm the prefect-server.service file is correct.
And we can see directly from cat /etc/systemd/system/prefect-server.service that the service file is still wrong.
Correct full unit file
ini
[Unit]
Description=Prefect Server
After=network-online.target postgresql.service
Wants=network-online.target
[Service]
Type=simple
User=root
WorkingDirectory=/home/prefect
Environment="PREFECT_HOME=/home/prefect/.prefect"
Environment="PREFECT_SERVER_API_HOST=192.168.29.151"
Environment="PREFECT_SERVER_API_PORT=4200"
Environment="PREFECT_SERVER_API_KEEPALIVE_TIMEOUT=60"
Environment="PREFECT_SERVER_LOGGING_LEVEL=DEBUG"
Environment="PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
Environment="PREFECT_SERVER_API_AUTH_STRING=astra:Network@5714"
ExecStart=/home/prefect/.venv/bin/prefect server start --host 0.0.0.0 --port 4200 --keep-alive-timeout 60
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
One more thing
You may also want to make the CLI auth consistent in your shell by setting:
bash
export PREFECT_API_AUTH_STRING="astra:Network@5714"
because the service uses PREFECT_SERVER_API_AUTH_STRING, while your CLI reads PREFECT_API_AUTH_STRING.
If you want, I can give you the exact nano edit commands and a final verified service file using an EnvironmentFile= instead, which is cleaner and much less error-prone.Shubham
07/08/2026, 7:55 PMMarvin
07/08/2026, 7:55 PMMarvin
07/08/2026, 7:55 PMbash
/etc/systemd/system/prefect-server.service
So the service name is prefect-server, not prefect.
That’s why this showed nothing:
bash
systemctl show prefect --property=Environment
Use:
bash
systemctl show prefect-server --property=Environment
Also, because your service file still contains the bad DB URL with < >, fix that first.
Do this exactly:
bash
sudo nano /etc/systemd/system/prefect-server.service
Replace this line:
ini
Environment="PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
with:
ini
Environment="PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://prefect:Network%405714@127.0.0.1:5432/prefect>"
Then run:
bash
sudo systemctl daemon-reload
sudo systemctl restart prefect-server
sudo systemctl show prefect-server --property=Environment
sudo systemctl status prefect-server
journalctl -u prefect-server -n 50 --no-pager
What you should expect
In the systemctl show prefect-server --property=Environment output, you should see something like:
bash
Environment=PREFECT_HOME=/home/prefect/.prefect PREFECT_SERVER_API_HOST=192.168.29.151 ...
including the DB URL without angle brackets.
Bottom line
Right now your shell config is okay, but your systemd service config is still wrong and you queried the wrong service name.
If you want, paste the output of:
bash
systemctl show prefect-server --property=Environment
systemctl status prefect-server --no-pager
journalctl -u prefect-server -n 50 --no-pager
and I’ll tell you immediately whether the service is truly running with Postgres.Shubham
07/08/2026, 8:00 PMMarvin
07/08/2026, 8:00 PMMarvin
07/08/2026, 8:02 PMbash
prefect version
Look for:
bash
Server:
Database: postgresql
or
bash
Server:
Database: sqlite
In your latest output, it already shows:
bash
Server:
Database: postgresql
So your current Prefect environment is using PostgreSQL.
Check the configured DB URL
bash
prefect config view --show-secrets | grep -i database
You should see something like:
bash
PREFECT_API_DATABASE_CONNECTION_URL='postgresql+asyncpg://...'
If it says sqlite+aiosqlite:///..., then it is using SQLite.
If Prefect is running as a systemd service
Check what the service is configured with:
bash
systemctl show prefect-server --property=Environment
If you see:
bash
PREFECT_API_DATABASE_CONNECTION_URL=postgresql+asyncpg://...
then the service is configured for Postgres.
If nothing appears, or it shows a SQLite path, then the service is not configured the way you expect.
Best runtime verification from logs
bash
journalctl -u prefect-server -n 100 --no-pager
This helps confirm what the running service is actually doing when it starts.
Most important caveat
There are two different things:
1. Your shell / CLI config
- checked by prefect version
- checked by prefect config view
2. Your running systemd service config
- checked by systemctl show prefect-server --property=Environment
- checked by journalctl -u prefect-server
So if you want to know whether the service is on Postgres or SQLite, don’t rely only on your shell.
For your case
From what you already posted:
bash
prefect version
...
Server:
Database: postgresql
That confirms the Prefect process in your current shell is using PostgreSQL.
But your systemd file still showed this broken line:
ini
Environment="PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://...>"
So to verify the service specifically, run:
bash
systemctl show prefect-server --property=Environment
journalctl -u prefect-server -n 50 --no-pager
If you want, I can give you a 3-command exact check to prove whether the running service is on PostgreSQL or SQLite.