score:0

Accepted answer

You can, as a_horse_with_no_name notes, use the database system identifier. However:

  • The sysid does not change when you clone a database via pg_basebackup, SAN snapshots, etc. The Timeline ID may increment, but doesn't always, depending on method used for copying.

  • The sysid does change if you dump and reload a database to a new instance, even though the database contents are the same.

  • Many PostgreSQL read/write master instances may have the same sysid if they're all cloned from a common pre-configured postgres in some container template or similar.

  • It's trivial to regenerate the sysid, or set it to whatever you want it to be.

  • The sysid is not preserved by pg_upgrade

so personally, I do not recommend using the sysid. If I had to do disaster recovery and restore a dump into a newly initdb'd database and your software locked me out, I'd be finding a new vendor and a lawyer.

It doesn't help that it's not currently accessible via SQL, only by using pg_controldata.

Definitely do not use the version string. It'll be the same for any set of deployments from the same set of packages, distributed binaries, or whatever.

There isn't really anything like what you want in PostgreSQL, and I'm not sure there can be because of the things that people routinely do. Cloning DBs, snapshots and restores, copying a DB for a QA/staging instance, etc, etc.


My personal advice: don't do this. I've had to break systems like this in business emergencies when the license system threatens business continuity. (It's rarely hard). I strongly advocate against tools with active license enforcement when I'm involved in purchasing. Dongles are even worse. Pay attention to the fact that even Microsoft uses "soft" license enforcement, where it helps you track compliance and warns you, but doesn't try to break the system if it thinks you're not in compliance. This is what the legal system is for.

Oh, if you really feel you must do this, Microsoft Windows systems have a SID. But your customers will hate you if they have to reinstall the OS.

Similarly, there's the hardware TPM. But they'll hate you even more if they restore an OS backup image to new hardware and the DB refuses to start.


More questions

More questions with similar tag