By hanh
I have a postgres server running as a backend for a low-usage flask site on a digital ocean droplet. The only thing that’s going in is small amounts of text.
Suddenly this happened:
2017-08-16 04:49:26 UTC [13529-1] FATAL: could not map anonymous shared memory: Cannot allocate memory 2017-08-16 04:49:26 UTC [13529-2] HINT: This error usually means that PostgreSQL’s request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 148488192 bytes), reduce PostgreSQL’s shared memory usage, perhaps by reducing shared_buffers or max_connections.
According to cat /proc/sys/kernel/shmmax:
SHMMAX is: 18446744073692774399 or 18e18 bytes! (Postgres documentation does say it’s bytes, not bits) How did the error message get 148488192 bytes? I guess some kind of overflow. But this value is crazy!
My droplet only has 512Mb of memory.
Am I missing something?
Clearly this isn’t the only thing that went wrong – why would a low usage site with which only puts ~2kb of text in a table at a time suddenly be using too much memory?
FYI: This is my first time using a database or running a website.
I’m doing it as a low-stakes learning exercise, so any pointers into other logs I should look at, changing/what is happening with SHMMAX, or what else to look out for would be greatly appreciated. It was running smoothly for a couple of months before this, and after rebooting the droplet, everything has continued to run smoothly.
The full Postgres logs were:
2017-08-16 04:49:17 UTC [1583-2] LOG: received fast shutdown request 2017-08-16 04:49:17 UTC [1583-3] LOG: aborting any active transactions 2017-08-16 04:49:17 UTC [1588-2] LOG: autovacuum launcher shutting down 2017-08-16 04:49:17 UTC [5146-1] user@user FATAL: terminating connection due to administrator command 2017-08-16 04:49:17 UTC [5149-1] user@user FATAL: terminating connection due to administrator command 2017-08-16 04:49:17 UTC [5147-1] user@user FATAL: terminating connection due to administrator command 2017-08-16 04:49:17 UTC [1585-1] LOG: shutting down 2017-08-16 04:49:17 UTC [1585-2] LOG: database system is shut down 2017-08-16 04:49:26 UTC [13529-1] FATAL: could not map anonymous shared memory: Cannot allocate memory 2017-08-16 04:49:26 UTC [13529-2] HINT: This error usually means that PostgreSQL’s request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 148488192 bytes), reduce PostgreSQL’s shared memory usage, perhaps by reducing shared_buffers or max_connections.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello,
I could suggest adding a bit more RAM to your server as described here:
https://docs.digitalocean.com/products/droplets/how-to/resize/
Or alternatively, you could add a swap file so that you have some additional buffer:
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.