LibPQ on the Raspberry PI

I have LibPQ working on a Windows machine. I am now trying to get it to work on a Raspberry PI 4. The RPI has 64 bit bookworm installed as Raspberry PI OS. It is up to date.

I installed Postgresql using the installation instructions at this site. This includes the installation instructions and the instructions for setting up the CLI.

Then going to a discourse discussion I included the steps on this discourse post.

When I type in either of the commands

conn = LibPQ.Connection("dbname=postgres")
conn = LibPQ.Connection("dbname=postgres user=jakez")

I get this error message

[error | LibPQ]: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?
ERROR: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?
Stacktrace:
 [1] error(logger::Memento.Logger, exc::LibPQ.Errors.PQConnectionError)
   @ Memento ~/.julia/packages/Memento/xnHxE/src/loggers.jl:463
 [2] handle_new_connection(jl_conn::LibPQ.Connection; throw_error::Bool)
   @ LibPQ ~/.julia/packages/LibPQ/CRtC5/src/connections.jl:127
 [3] LibPQ.Connection(str::String; throw_error::Bool, connect_timeout::Int64, options::Dict{…}, kwargs::@Kwargs{})
   @ LibPQ ~/.julia/packages/LibPQ/CRtC5/src/connections.jl:0
 [4] LibPQ.Connection(str::String)
   @ LibPQ ~/.julia/packages/LibPQ/CRtC5/src/connections.jl:265
 [5] top-level scope
   @ REPL[4]:1
Some type information was truncated. Use `show(err)` to see complete types.

I am not sure what to do next.

Found the problem. Postgres tends to be case insensitive, but the database name must be in lower case for the RPI, where it does not need to be for windows. I also needed to add the port and host to the DBInterface.connect command. The example is:

Works for Windows
dbread = "Test2"
DATABASE_USER = get(ENV, "LIBPQJL_DATABASE_USER", "postgres")
DATABASE_PASSWORD = Password
conn = DBInterface.connect(FunSQL.DB{LibPQ.Connection}, 
"dbname=$dbread user=$DATABASE_USER password=$DATABASE_PASSWORD")

Changes for RPI
dbread = "test2"
conn = DBInterface.connect(FunSQL.DB{LibPQ.Connection}, 
"dbname=$dbread user=$DATABASE_USER password=$DATABASE_PASSWORD
host=localhost port=5432")
1 Like