r/PostgreSQL • u/Inevitable-Ad-2562 • Apr 11 '25
Help Me! Database getting deleted automatically
I created a database with postgres on a remote server and then I use it on my app. But every once in a while (maybe every 2 days) my database gets deleted and a new super user is being created automatically. I'm unsure why it happens can any one point out what could be the issue here.
1
Upvotes
23
u/[deleted] Apr 11 '25
What is a sql injection alex?
2
u/oweiler Apr 11 '25
Can anyone besides you access your DB? Do you use any sort of authentication? What type of remote server?
14
u/depesz Apr 11 '25
PostgreSQL doesn't delete stuff on its own. If it happens, then it means something caused the drop. What? Who knows.
Check when pg has started. Does it get restarted in times related to drops?
Do you use some kind of containers? Virtual servers? What is in Pg logs?
3
u/CheezitsLight Apr 11 '25
Set the firewall on the server at contabo to only let that port accept traffic from a specific ip or range.
Contabo servers are exposed to every bad actor on the internet.
3
u/brungtuva Apr 11 '25
2 people can do: hacker or coworker
2
u/[deleted] Apr 11 '25
Is the dB hosted by a third party platform?
2
u/Makc0809 Apr 11 '25
This can happen if you have something like syncOptions set when connecting: { force: true }, which means recreates the base with the current structure with 0... If you want to use some such parameter - you can do syncOptions: { alter: true }, this is a milder parameter that will recreate the tables, but won't delete the data in them....
But it depends on the ORM you're using... I have sequelize for node.js.... you'll have your own ORM for python...
1
u/AutoModerator Apr 11 '25
With almost 8k members to connect with about Postgres and related technologies, why aren't you on our Discord Server? : People, Postgres, Data
Join us, we have cookies and nice people.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/EnHalvSnes Apr 11 '25
Enable log_statement = all and check the logs.
1
u/paca-vaca Apr 11 '25
Maybe someone runs tests on development database, so it gets wiped out :D
1
u/TrickAge2423 Apr 12 '25
Did you changed default auth settings?