pg_sql | Unsorted

Telegram-канал pg_sql - PostgreSQL

2830

English speaking PostgreSQL public chat. This group is for discussions on PostgreSQL-related topics and strives to provide best-effort support as well.

Subscribe to a channel

PostgreSQL

Ah, but isn't that only valid for BIG5?

Читать полностью…

PostgreSQL

If your software does not implement safeguards against SQL injection, postgresql will happily eat and execute whatever it was given as a query

Читать полностью…

PostgreSQL

I suggest you look at the release notes for all of the versions in between and verify if there are any changes of note

Читать полностью…

PostgreSQL

Upgrading from 13.12 to 13.19

Will there be any issue if I do direct upgrade in application end ?

Читать полностью…

PostgreSQL

Can anyone help to store failed login attempt

Читать полностью…

PostgreSQL

So you're calling
https://peps.python.org/pep-0249/#fetchall
?
Then it's what it says there:
a sequence of sequences (e.g. a list of tuples)

Читать полностью…

PostgreSQL

The question is: returns *where*? Perl? Python? GO? Java?
What you show looks like the result of fetchall_arrayref() or something similar.

Читать полностью…

PostgreSQL

Hi
Postgre return all data like this: [(-1002438998547,)]

Yes? or im dead wrog?

Читать полностью…

PostgreSQL

Check max_slot_wal_keep_size setting

Читать полностью…

PostgreSQL

How many users do you plan to have?

Читать полностью…

PostgreSQL

In your exact situation, in my case I just collected users and then did a mass update once I reached several hundreds or a certain time with no updates

Читать полностью…

PostgreSQL

Hi can anyone help me with the online coding test

Читать полностью…

PostgreSQL

Correct.
I picture this like this: Exclusive Locks lead to a kind of hour glass effect to the otherwise parallel locking queue:
```
||||||||
||||||||
\ /
\ /
\ /
|
/ \
/ \

```

Читать полностью…

PostgreSQL

so since PID_1 is doing accesssharelock and this conflict with TRUNCATE (EXCLUSIVELOCK) - it will wait for the PID_1 to finish and only then TRUNCATE will begin?

Читать полностью…

PostgreSQL

i have a PID_1 which is doing AccessShareLock on table
and then there's another PID_2 that is doing AccessExclusiveLock (truncate) on the same table.
does PID_2 needs to wait for PID_1 to finish first? hope someone can explain me how the locks works

Читать полностью…

PostgreSQL

I guess @Tipstertipss means CVE-2025-1094
Be aware that there will be another release this Thursday, you should wait for that. Apart from that, I'd not expect any issues, but you should of course stage the upgrade (i.e., don't upgrade PROD straight away).

Читать полностью…

PostgreSQL

Updating will not save you from sql injection

Читать полностью…

PostgreSQL

This is to avoid sql injection

Читать полностью…

PostgreSQL

You might be interested in https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-CONNECTIONS

Читать полностью…

PostgreSQL

I undrestand, let fix it
Thanks

Читать полностью…

PostgreSQL

This is python
Yes thats right, thanks

Читать полностью…

PostgreSQL

You're doing something wrong probably with your joins, or storage

Читать полностью…

PostgreSQL

It could cause a slot to be dropped if the WAL data exceeds the allowed limit. 

Читать полностью…

PostgreSQL

hello, I create physical replication slot and it immediately dissappears, why it is happening

Читать полностью…

PostgreSQL

But I had millions of stored users, so it was impractical to run on every message anywau

Читать полностью…

PostgreSQL

Hi, sorry if this question might seem stupid, and sorry for this wall of text, but I have this question:

having these tables (which represent the state of Telegram chats/users and their usernames, from the perspective of a bot):

CREATE TABLE IF NOT EXISTS users (
user_id BIGINT PRIMARY KEY,
first_name TEXT NOT NULL,
last_name TEXT
);

CREATE TABLE IF NOT EXISTS chats (
chat_id BIGINT PRIMARY KEY
-- other fields...
);

CREATE TABLE IF NOT EXISTS usernames (
username VARCHAR(32) COLLATE case_insensitive UNIQUE,
user_id BIGINT UNIQUE,
chat_id BIGINT UNIQUE,

FOREIGN KEY(user_id) REFERENCES users(user_id),
FOREIGN KEY(chat_id) REFERENCES chats(chat_id),
CHECK((user_id IS NULL) != (chat_id IS NULL))
);


and needing to run a query/procedure, for every message received (I need to have an overview of usernames as updated and complete as possible), which can be even thousands of times per second, that:
- if the user that sent the message doesn't have a username [anymore], deletes it from the usernames table; otherwise, go ahead
- insert the username and chat/user_id in the table, deleting/updating any existing conflicting record

what would the most efficient way to do it?
At first I (naively, maybe) thought to do something very simple like this (not tested, just to give an idea):
CREATE OR REPLACE PROCEDURE update_username(n_username VARCHAR(32), u_user_id BIGINT, u_chat_id BIGINT) AS $$
BEGIN
IF (u_user_id IS NULL) = (u_chat_id IS NULL) THEN
RAISE EXCEPTION 'Cannot both set user_id and chat_id (or neither)';
END IF;

DELETE FROM usernames
WHERE (user_id = u_user_id) OR (chat_id = u_chat_id);

IF n_username IS NOT NULL THEN
INSERT INTO usernames(username, user_id, chat_id)
VALUES (n_username, u_user_id, u_chat_id)
ON CONFLICT (username) DO UPDATE SET user_id = u_user_id, chat_id = u_chat_id;
END IF;
END;
$$ LANGUAGE plpgsql;


but discussing it with another person (which has more experience than me, and has had to solve the same issue) it seems that this would be too "expensive", and that in most cases it would be actually more efficient to remove the first DELETE query, leave the INSERT as is, and just handle possible the sqlstate 23505 (or even the exception from the programming language in use..) as appropriate (so in most cases only the INSERT query would be executed)

What I would like to ask you is: is this advice true? or was my first trial already efficient enough? or is there a better method to achieve this?

Читать полностью…

PostgreSQL

Can lead to .... interesting times ... ask me how I know ;-)

Читать полностью…

PostgreSQL

Works that way in most of the reliable rdbms. You are probably reading from table or updating it so modification to it's structure has to wait.

Читать полностью…

PostgreSQL

https://xata.io/blog/anatomy-of-locks

Читать полностью…

PostgreSQL

Hi everyone, i hope you have a good day!

İ have one difficulty, i need to show all users and roles and them all permission for all database in server in table based.


Result must to be like this:

User1 db_A table_example select,update

User1        db_B   table_example2  select

User2 db_A table_example select

User2 db_B table_example2 select,update

Читать полностью…
Subscribe to a channel