Quick intro to Postgres for developers

postgresIn this article, a quick guide to the most commonly used Postgres commands

INSTALL

sudo apt-get install postgresql postgresql-contrib

ADMIN OPERATIONS

Create superuser from the commad line

sudo -u postgres createuser –superuser digideps

Create database from command line

sudo -u postgres createdb newDatabaseName

Login via command line (postgres is the default root user)

sudo -u postgres psql [dbname]

DEVELOPER OPERATIONS / QUERIES

Describe table1

d+ table1;

Change password of the postgres user

password postgres

Grant permission on db1 to user1

grant all privileges on database db1 to user1

List databases

l

List users

du

List tables in a db

dt

IMPORT/EXPORT

Export db snapshot

sudo -u postgres pg_dump dbname —clean > dump.sql

Import db from snapshot

sudo -u postgres psql dbname < dump.sql

Startup notes

Interesting article shared by some colleagues. If you work for a startup I’m sure you’ll find truth in most of the points the post raises. I’ll share some parts of it.

Don’t waste your time in crappy startup jobs. « Michael O.Church

Startups often involve, for engineers, very long hours, rapidly changing requirements, and tight deadlines, which means the quality of the code they write is generally very poor in comparison to what they’d be able to produce in saner conditions. It’s not that they’re bad at their jobs, but that it’s almost impossible to produce quality software under those kinds of deadlines

The result of this is that the engineer’s job isn’t to build great infrastructure that will last 10 years… because if the company fails on the marketing front, there will be no “in 10 years”. The engineer’s job is to crank out features quickly, and keep the house of cards from falling down long enough to make the next milestone. If this means that he loads up on “technical debt”, that’s what he does.

A competent manager can do a lot for a person’s career that he wouldn’t realistically be able to do on his own. Still, the idea that joining a startup means not having a boss is just nonsense.

Git rebase and remote operations

Taken from http://git-scm.com/book/

When you rebase stuff, you’re abandoning existing commits and creating new ones that are similar but different. If you push commits somewhere and others pull them down and base work on them, and then you rewrite those commits with git rebase and push them up again, your collaborators will have to re-merge their work and things will get messy when you try to pull their work back into yours.

Know your framework !

I agree with this article

you need to know your framework before saying that is fast or not. If you need to save some ms (if that helps, does it ?), profile and optimize. With some simple optimization (the one in the article + apc cache of conf files if you have them) you can easily dispath a ZF route in < 30 ms. Now, do you really need it to save more ms ? profile the whole system, probably your bottleneck are other things, inside and outside your server

PHP Framework Benchmarks: Entertaining But Ultimately Useless | Pádraic Brady

To create a positive benchmark, you need to understand that all frameworks were born as festering piles of unoptimised stinking crap. They were all born bad and get worse with age. This sounds quite sad, but actually it’s an inevitable compromise between performance and features. It’s also a compromise between performance and ease-of-use. So you see, performance is unfairly faced by two opponents: features and ease-of-use. All performance is sacrificed in the name of serving the needs of rapid development, flexibility, prototyping, and making your source code look prettier than the other guy’s. As if.