By bmvr

2019-05-07 15:59:36 8 Comments

I'm trying to understand how can I set the work_mem setting on the Postgres(v10) for a single connection/session.

Currently I'm connection to my Postgres Instance in the cloud through a NodeJs app using a query string as showing bellow:


I know that you can set parameters in the connection string such as connection_timeout and so on, but I can't find anyware how to set the work_mem for the current connection/session.


@jjanes 2019-05-07 17:46:28

Only a select list of parameters are allowed directly in the connection string. Others must be imbedded via the "options" parameter. This leads to much ugliness and escaping and quoting challenges.

Here is an example that sets work_mem to 1234 kB:

psql "postgresql://[email protected]/jjanes?connect_timeout=10&options=-c work_mem%3D1234"

@a_horse_with_no_name 2019-05-07 18:09:10

I don't think a connection string for Node.js supports the -c parameter

@bmvr 2019-05-08 10:20:12

Hello, I've tried it, didn't work. I had to set work_mem = 'xxMB' before when I opened the connection, this was not what I wanted but well.. it works.

@jjanes 2019-05-08 13:31:07

Ok, -c might be libpq specific. Can you tell what library within nodejs you are using to connect? There seems to be several. Abstracting the connection logic to a routine which can do housekeeping commands before handing the connection back is probably a better design anyway. Rather than stuffing all the logic into a connection string which then gets fired from multiple parts of the code.

Related Questions

Sponsored Content

1 Answered Questions

1 Answered Questions

1 Answered Questions

4 Answered Questions

[SOLVED] PostgreSQL 9.1 Hot Backup Error: the database system is starting up

  • 2012-04-19 15:17:39
  • Jen
  • 71197 View
  • 17 Score
  • 4 Answer
  • Tags:   postgresql backup

1 Answered Questions

[SOLVED] Setting up PostgreSQL Connection with DBVisualiser

Sponsored Content