Starting with Pg – where is the config?

Over the years I saw some people find themselves in position where they have to start dealing with PostgreSQL with minimal, or none, prior exposure. This leads to problems with seemingly easy tasks – how to change config? How to find stuff in logs?

So I decided to write some blogposts to be able to point such people to pre-made tutorials.

And I start today, with information on how to find PostgreSQL config files.

Continue reading Starting with Pg – where is the config?

How to install and configure PostgreSQL Debian/Ubuntu – for developer use – part 2

In previous post I showed how I'd install PostgreSQL for developer.

But that's not all. Now we need to add some configuration. What, how, where?

Continue reading How to install and configure PostgreSQL Debian/Ubuntu – for developer use – part 2

How to install and configure PostgreSQL Debian/Ubuntu – for developer use – part 1

Recently I spent some time thinking about what can be improved when it comes to helping new users start using PostgreSQL.

One thing that almost immediately jumped to my mind is – how to install PostgreSQL? The task is theoretically simple. But there are always some caveats – which packages to use, what to configure in the beginning, where to find config files and logs.

With that in mind I decided to write a howto based on my ideas on what is right. These do not necessarily mean that these are the best for everybody, but I think this is a good start for anyone wanting to start their adventure with PostgreSQL.

Final note of warning – this post is for installing and setting PostgreSQL on developer workstation. As in: server where user can do anything, and we don't really care about security. Please do not configure production servers using this howto.

Continue reading How to install and configure PostgreSQL Debian/Ubuntu – for developer use – part 1

How to run short ALTER TABLE without long locking concurrent queries

Recently I've seen case like:

  1. application had to add column to table.
  2. application ran ALTER TABLE ADD COLUMN (without default!)
  3. everything stopped for many MINUTES

Why? How to avoid the problem?

Continue reading How to run short ALTER TABLE without long locking concurrent queries

How to play with upcoming, unreleased, PostgreSQL?

Lately reader of my blog asked about some detail, and then in next comment said that he doesn't have PostgreSQL 12 (which is currently developed version of Pg) available.

Well, I answered the original question, but I figured that if someone is reading my Waiting for … series, then it would make sense that such person could play with devel Pg herself.

So, here is how to get it done.

Continue reading How to play with upcoming, unreleased, PostgreSQL?

Automation for doing stuff in multiple windows in tmux

Tmux is terminal multiplexer. Kinda like old screen, but with much more functionality.

When I work on my servers, it's pretty common that I have to do the same things to multiple servers. To make my life easier I start tmux, and in there start many “windows", each related to work on single server.

I name the windows in a way that let's me quickly find them, without false positives.

For example, if I'd have to upgrade servers db1..db5 then I'd create windows “up-db1" .. “up-db5", and each window would work on single server.

This is already scriptable – let's assume I'd want to show uptime in all of the windows, I can:

tmux lsw -F '#W' | grep -E '^up-db[0-9]+$' | xargs -r -d$'\n' -I% tmux send-keys -t % uptime Enter

But this gets tedious fast.

Continue reading Automation for doing stuff in multiple windows in tmux

Converting list of integers into list of ranges

Yesterday someone on irc asked:

i've a query that returns sequential numbers with gaps (generate_series + join) and my question is: can is somehow construct ranges out of the returned values? sort of range_agg or something?

There was no further discussion, aside from me saying

sure you can. not trivial task, but possible.
you'd need window functions.

but it got me thinking …

Continue reading Converting list of integers into list of ranges