[GNC] Postgress connection string for nonstandard port

Geert Janssens geert.gnucash at kobaltwit.be
Sun Feb 26 11:04:20 EST 2023


Op donderdag 23 februari 2023 22:00:12 CET schreef Bob Treumann:
> Thanks for all the feedback.   I will share my learnings;
> 
> The database must be created before you connect to it.    The install
> process creates all the tables in the Public schema in that database once
> it connects successfully.

If your postgresql user has proper database creation rights, the database doesn't have to 
exist prior.

> 
> Geert Janssens referenced the code where he could tell that the appended
> port should work.
> Geert, can you tell me where to find that?     I would like to see if I can
> modify it to connect to my chosen database and schema rather than using the
> public schema in a dedicated database.

I can give you a few pointers, but I'm afraid the whole path is not that straightforward.

I have started from the code that reads the database parameters:
https://github.com/Gnucash/gnucash/blob/maint/gnucash/gnome-utils/dialog-file-access.c#L71[1]
That code will eventually call 'gnc_uri_create_uri' in
_https://github.com/Gnucash/gnucash/blob/maint/gnucash/gnome-utils/dialog-file-access.c#L9_8
Note the port parameter is set to 0, which suggests to omit adding a port number to the uri 
by code. However if the host parameter contains a port part, that will be retained in the final 
uri, and that's how you can pass a non-standard port when entering database parameters.

> 
> I mentioned in another post that Postgress creates multiple schemas in a
> single database.    That is my preferred way of operating because I can
> read and write to other schemas without connecting across databases.    I'm
> not even sure if PG supports cross database connections.

There is no support for schemas other than the default, because schemas are a feature 
specific to postgresql and the same database code in gnucash also has to work with mysql 
and sqlite.

If you want to look into implementing some kind of generic table prefix (which could 
translate into a schema in posgresql and just a name prefix in the other databases), you will 
probably have to combine amandments in the gnc_uri code with changes in the dbi backend 
code found here
https://github.com/Gnucash/gnucash/tree/maint/libgnucash/backend/dbi[2]

Regards,

Geert

--------
[1] https://github.com/Gnucash/gnucash/blob/maint/gnucash/gnome-utils/dialog-file-access.c#L71
[2] https://github.com/Gnucash/gnucash/tree/maint/libgnucash/backend/dbi


More information about the gnucash-user mailing list