Monthly Archives: May 2020

How to Drop a User

Do you have some “dead” users in your production database? Users which belonged to some former employees, who are long gone, but their Postgres users still maintain their ghostly presence in your environment? Just be honest :). I know that all of us should have some process in place to drop a user when somebody leaves the company. Most of the time, we are doing it promptly. But sometimes…

Sometimes, when we are trying to drop a user, we get an error: that user owns some objects. And there is no “DROP CASCADE” option for a user. Moreover, most likely, you do not want to drop cascade because that user might own some critical objects you do not want to lose!

Yes, we should not have such situations in the first place, and you might even have a policy stating that objects should never belong to the individual users, only to the group roles. But things happen. Maybe, somebody was in a hurry fixing production issues. Maybe, something was created “temporarily.” In any case, you can’t drop this user. You need to reassign the objects the user owns to the correct user/role. You need to revoke permissions. In case you can understand what in the world these permissions mean!

Several weeks ago, I was facing one of these situations. I successfully reassigned objects and revoked permissions, except for a couple. These last ones were weird, and I could not revoke then no matter what! What I mean, I was issuing a revoke command, it would complete successfully, but permissions still stayed! Apparently, I did not know what I was doing :).
I had to rely on the last resort – ask Grandpa Google. And I quickly discovered a command I didn’t use before: DROP OWNED BY. Looks like exactly what I wanted, almost DROP CASCADE, right? Wrong! Because in contrast to DROP CASCADE, it won’t tell you what exactly it dropped! When you issue DROP CASCADE in a transaction, it would tell you which objects it is going to drop, and you can make sure you are not accidentally dropping something you didn’t mean to drop. But this command executes in dead silence!

I can’t even describe how scary it was to actually press ENTER:)

… In case you think I have no fear!

Leave a comment

Filed under Data management, SQL

Introducing NORM repo

In the course of the past two and a half years, I gave an endless number of talks about “our JSON thing,” which we now call NORM. And since my very first presentation, people would ask me whether I can show an example of the code developed using this approach. And I never had a good answer. I do not know what took me so long, but now I finally have it. 

For those who love an idea of the wold without ORM, and who want to start “doing it the right way,” the working example of the NORM technology can be found here. 

Please take a look! We are planning to add to this repo a small java program that will use the PostgreSQL functions. 

And I would love to hear from people who would

  • clone this repo and let us know what does not work or how documentation can be improved
  • develop a simple app on ruby on rails, which will use the same Postgres functions 
  • utilize the same approach with any other database/application combination

Looking forward to the feedback!

2 Comments

Filed under Development and testing, research, SQL