146 questions
1
vote
1
answer
75
views
Accessing postgres db using pgxpool in a goroutine
I have created a function to return the db connection of a postgresdb using pgxpool. But I don't want to create multiple pools since i will be calling this function each time to execute a query.
Since ...
0
votes
1
answer
99
views
Unable to Authenticate to Docker image via Golang
I am new to Docker and Golang. I am trying to run Golang server locally and connect it with my postgres docker image.Basically I want the DB to run as docker container with persitant volume
Error
PS C:...
1
vote
1
answer
403
views
Why transaction timeout in pgx doesn't work
I used to use the pq library, now I want to use pgx. I have a task to abort a transaction if it has been running in the db for too long. pq is able to abort a transaction as soon as the context has ...
1
vote
2
answers
139
views
Do prepared statements in PostgreSQL respect shared_buffers memory limits?
Recently I observed OOMs in a PostgreSQL 16 server used by an application which made heavy use of prepared statements. Memory would gradually grow until hitting an OOM.
How to limit the usage of ...
0
votes
1
answer
690
views
When using rows.Values() in Go's pgx, How can I know if the value was NULL without resorting to use rows.Scan()?
I want to iterate over the values in a row with rows.Values() and that works but there is no clear way how can I check if each value has NULL (valid/invalid):
rows, err := conn.Query(context....
1
vote
1
answer
508
views
how to use bool type with sqlc
I'm learning to use sqlc (with pgx)
my sqlc.yaml
version: "2"
sql:
- engine: "postgresql"
queries: "query.sql"
schema: "schema.sql"
gen:
go:
...
1
vote
0
answers
54
views
Function FetchUserForAuthV1 Fails Under Concurrency, While FetchUserForAuth Performs Well
I have two functions with similar functionality that I use to test concurrency. However, FetchUserForAuthV1 starts throwing errors with fewer requests compared to FetchUserForAuth. I’m sharing code ...
1
vote
1
answer
788
views
How does `jackc/pgx` works with multiply hosts
I have a PostreSQL cluster where I have a master and a slave. I have seen that pgx/pgxpool supports simultaneous connection to multiple hosts, but I do not understand how requests will be executed ...
2
votes
0
answers
52
views
How can I run migrations, using go-migrate, inside cloud run against a postgres cloud sql instance? [duplicate]
I've been stuck this issue for the past few days. Here is my database that connects to the DB instance and attempts to run migrations against it:
func connectToDb() (*pgxpool.Pool, error) {
...
2
votes
2
answers
4k
views
Golang squirrel query builder build query which does not execute?
I have a code which does unit testing, where I prepare a database for the tests (I do not use sql-go-mock), so I want to insert returning id with a simple sql INSERT INTO, but for some reason pgx ...
-1
votes
1
answer
145
views
Changing user password using postgres go client
Hi I'm trying to change user's password in postgres using pgx/v5 driver in Go
_, err = conn.Exec(context.Background(), "ALTER USER $1 WITH PASSWORD $2", username, password)
if err != nil {
...
2
votes
0
answers
243
views
pgxpool.ConnectConfig does not recognized and caouses build error
I have used the ConnecConfig function to create a pool. However, I am not satisfied with building it at the code below.
Compiler message: ConnectConfig not declared by package pgxpool
package main
...
3
votes
1
answer
1k
views
pgx scan query with join into nested struct
I have an SQL query that joins 2 tables:
SELECT locations.id as id, locations.name as name, states.id as state.id, states.name as state.name FROM locations INNER JOIN states ON states.id = locations....
2
votes
3
answers
4k
views
Clean way to manage database transactions in golang
I am trying to figure out a good solution for managing database transactions in Golang and use the same transaction between different services.
Let's say I am building a forum, and this forum has ...
2
votes
1
answer
2k
views
Executing Multiple SQL Statements in Go using pgx
Will this work with pgx in Go?
func CreateTable(
ctx context.Context,
pgxPool *pgxpool.Pool,
) error {
const tableQuery = `
INSERT INTO table (status)
VALUES ('Active');
...