Getting [error] GenServer #PID<0.398.0> terminating ** (Postgrex.Error) FATAL 08P01 (protocol_violation) no such database

Hey,

If I am creating a new install and want to use a remote database from the start.

I have attempted to do several different ways Im not sure which to post as far as results.

Im looking for an order of operations.

Do I need to create the app with/wo database first.
if I should get the base app working first then migrate.
or change the credentials just after mix phx.new
etc

the end result would be to go straight to production with a ‘fullstackphoenix’ starter template app to fly.io with a managed database at digital ocean.

but even as far as just a blank fresh install, many, I’m not having success doing this configuration just yet.

I can get a blank install onto fly.io no issues but as soon as I introduce the external database to dev.ex and/or runtime.ex (local or deploy, usually same issue) I get:

05:27:10.307 [error] GenServer #PID<0.328.0> terminating
** (Postgrex.Error) FATAL 08P01 (protocol_violation) no such database: postgres
    (db_connection 2.4.3) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 4.1.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

Any pointers would be appreciated.

This seems more of a issue related to configuration. I would recommend using runtime configuration for deployments as it makes configurations easier.

As for migrations, they are pretty flexible and highly depend on your requirements. I’m not sure how fly.io deployments work, however if it creates a release for you, then you won’t have mix in your project anymore, so you have to create your own custom migrator you can find and example here.

2 Likes

Thank you. Appreciate it.

Hi @humankindof this seems like a duplicate of ** (Postgrex.Error) FATAL 08P01 (protocol_violation) no such database: postgres - #3 by humankindof, can you elaborate on the difference?

1 Like

Yes.

Thanks for asking.

Deployment has always given me difficulty. So i figured i would tackle that first with this project and get it set up how i wanted for continuous deployment and go from there.

i was playing around with runtime.ex and .env for some time after your post.

And i was creating another error that came up before the postgrex.error. So it was never really solved. It just changed and i thought it solved.

Your post helped me to realize i trying to solve too many levels of difficulty at the same time. -still a bit of a noob. -

So i took a step back and did a Clean phx.new basic install and deploy to fly. Easy peasy.

I can can change postgres credentials and database on localhost. Deploy to fly.io with their unmanaged database. No issues. 5 minute install.

But the moment i change to remote postgres server, and that is the only thing i change. Deps.get, ecto.Drop, create, migrate. Any or all of these commands, same postrex.error.

Dev env. Only config is Secrets and certs and database url exports. Pg_hba.conf config on remote server. Thats it. No other changes or config. No releases. No prod env.

Does not matter if i am only running localhost:4000 or am deployed out of the box to fly.io. Same thing.

I can ssh into remote database no issue.

If the ca cert is missing i get that error first and adding cert causes issue resolved.

I have had this running before, couple days ago, local server to remote db.

Never been able to get it going on fly.io but i think it was an issue i have to take up with fly.

But now i cant get it to go local. And i dont understand the error. Thought maybe system.env issue or something. I dont know

Im gonna get into the releases and runtime setup deeper and see if that solves it. But not sure if chasing my tail. It should setup fine while in dev.