7 ms·
PostgreSQL Basics by Example
- pjungwir 13y agoNice intro. One great trick if you want to learn more about the system tables is `psql -e`. This will show the queries used internally by all the \d, \u, etc. commands.
- Oculus 13y agoBookmarked. Definitely could've used this post when I was just starting with PostgreSQL!
- darthdeus 13y agoI'm glad to hear that :) I've had problems with this for so long that I finally decided to put all of the information together. I'm planning to cover more things about PostgreSQL, mostly using pg_dump, pg_restore, pg_upgrade, initdb etc., just the regular things you should know when using it on your own VPS.
- pavanred 13y agoI would definitely follow this then. I was just about to say that I hope this develops into part 1 of a queue of topics covered in a similar way. I just started with PostgreSQL and this is very helpful.
- workhere-io 13y agoAlso worth noting for those who are starting out with PostgreSQL: The easiest way to install it on your Mac is using Postgres.app (http://postgresapp.com http://postgresapp.com).
- chourobin 13y agoAs much I like mattt's work, I dont understand, why is this needed. brew install postgres is just as easy and in my experience Postgres.app is not well maintained and uses an older version.
- southpolesteve 13y agoI've personally helped 4 people setup Postgres on a recent model macbook with OSX Mountain Lion for Rails dev in the last 6 months. Every one has been terrible. Issue with sockets, issues with file permissions, issues with previous attempted installs, issues with setting up database users. Postgres.app just works and it is awesome.
- chourobin 13y agoThats interesting, I've never had an issue with the homebrew installation. The readme details 1 or 2 lines to get everything set up for the first time. I suppose osx built-in installation may cause conflicts.
- skndr 13y ago> I suppose osx built-in installation may cause conflicts. This is a consistent source of trouble when installing Postgres. Usually, this involves looking up the right places to modify the path and sometimes needing to change permissions/ports.
- misiti3780 13y agohere is the one I was having, http://stackoverflow.com/questions/12472988/postgres-could-not-connect-to-server-no-such-file-or-directory http://stackoverflow.com/questions/12472988/postgres-could-n... postgres app fixed it
- darthdeus 13y agoTo be honest I've spent about 4 hours last week trying to install homebrew PostgreSQL on a friends MacBook ... it took me forever to figure out why it wasn't connecting to the right socket, just because he had some things out of date :\ While it is really easy to install most of the time, I'd say the Postgres.app works well for people who aren't developers but need to use PostgreSQL.
- chourobin 13y ago
- MoOmer 13y agoFor my Mac, I typically use the enterprise graphical install[1]. If you're comfortable with command line, you really can't go wrong on most Linux flavors with the great documentation on the project website[2]. [1] http://www.enterprisedb.com/products-services-training/pgdownload#osx http://www.enterprisedb.com/products-services-training/pgdow... [2] http://www.postgresql.org/docs/9.2/static/install-procedure.html http://www.postgresql.org/docs/9.2/static/install-procedure....
- jpitz 13y agoThat may be the easiest way, but if your intention is to do serious, heavy-duty work with PostgreSQL, please do yourself a favor and learn how to compile and install from source.
- workhere-io 13y agoI've done some benchmarks with millions of rows, and a default PostgreSQL installed via apt-get on Ubuntu works fine. I doubt whether the majority of PostgreSQL users really need to install from source (especially considering how much harder it makes upgrades).
- jpitz 13y agoI didn't say it was faster, and I didn't say the majority needed to do it. The reason is to be able to customize your build and/or apply patches. Tom Lane fixed a production bug I reported in hours and this got me running fairly quickly.
- asdasf 13y agoWhere do people get this weird idea that typing "make" creates some sort of magic that makes the software faster or more stable or somehow better than having someone else type "make"?
- jtreminio 13y agoIt would be much better to keep it all inside a local VM.
- workhere-io 13y agoIf your purpose is to emulate your production environment fully, then yes. But if you're in the development phase weeks or months before going live, a virtual machine often has no real purpose and takes up a lot of RAM.
- jtreminio 13y agoI disagree. Just look at the people in this thread asking how to install it. In a VM you will mimic what you will eventually do, and installation is an apt-get or yum away. If someone is learning off of, say, Windows, their experience may possibly be quite different to what they will experience if they run this within a VM.
- workhere-io 13y agoJust look at the people in this thread asking how to install it They are talking about how other installation methods than Postgres.app can be difficult. Which is exactly my point: If you're on Mac and you want to get started with PostgreSQL easily, Postgres.app is the way to go.
- adwf 13y agoWhilst not perfect, pgadmin can also be helpful. I find it particularly useful for keeping an overall view of multiple databases/servers. http://pgadmin.org/ http://pgadmin.org/
- nucleardog 13y agoAs someone who has spent the last few days trying to become familiar with pgsql: yes. Don't be intimidated by all the options it offers. It makes things really easy and - more importantly imho - shows you the SQL it runs for every command. So far it seems a great way to learn pgsql coming with some background in SQL, if you want it to be.
- lukes386 13y agoOn a somewhat related note, I'd love to see a more intermediate resource on how to really leverage PostgreSQL in your applications. As someone who primarily works with Rails, I feel like I use about 1% of PostgreSQL's power.
- jacques_chester 13y agoWhich is how Rails wants you to use PostgreSQL. Their opinion is that logic belongs in the app, not the database.
- lukes386 13y agoYes, that's true. The approach has it's drawbacks though (validates_uniqueness_of being a prime example). As much as I like Rails, I sometimes wish it were designed with the database playing more of a role than just dumb storage. Defining things like validations in Ruby is certainly nice and easy, but the database is much better suited to actually enforcing such constraints.
- steveklabnik 13y agoIn general this is true, but with Rails 4, we added a lot of Postgres specific features to ActiveRecord, so you can actually take advantage of all the awesomeness Postgres has to offer. Check out this blog post: http://blog.remarkablelabs.com/2012/12/a-love-affair-with-postgresql-rails-4-countdown-to-2013 http://blog.remarkablelabs.com/2012/12/a-love-affair-with-po...
- jacques_chester 13y agoHas the actual philosophy changed though? When I first got to Rails it seemed that databases were considered as a bothersome but unavoidable necessity; flat files with a funny accent, instead of an essential and powerful ally in the fight against entropy and error.
- integraton 13y ago
- mistermcgruff 13y agoRepeat after me: set work_mem to 'XXXGB'; set maintenance_work_mem to 'YYYGB'; swing away!
- kibibu 13y agoThis annoys me so much about PostgreSQL. Why not have useful defaults?!
- ilikepi 13y agoThe defaults are useful in that they reflect a configuration that is appropriate to get the system running on a large variety of hardware. It's not really the responsibility of the Pg developers to guess at the "best" settings for any specific environment, because environments and configurations vary greatly.
- rgbrenner 13y agowork_mem is a per-sort setting. So if you have 20 users connected, running a single query with 4 sorts each, that's 80 x work_mem. If it's set to GB anything, that's going to get out of hand very fast. I recommend this guide.. it's a good start: http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Serve...
- wfn 13y agoMore like, "set shared_buffers", "set effective_cache_size".. Also, seconding rgbrenner re: "Tuning your PostgreSQL server" article.
- fphilipe 13y agoCraig Kerstiens from Heroku periodically posts great articles about PostreSQL [1]. They're all really worth a read, especially [2] which is in the nature of the original link. [1] http://www.craigkerstiens.com/content/ http://www.craigkerstiens.com/content/ [2] http://www.craigkerstiens.com/2013/02/13/How-I-Work-With-Postgres/ http://www.craigkerstiens.com/2013/02/13/How-I-Work-With-Pos...
- craigkerstiens 13y agoFirst, thanks for the callout. Happy to shamelessly accept plugs, and to add to it there's a guide I curate and a weekly newsletter with interesting articles as well: http://www.postgresguide.com http://www.postgresguide.com http://www.postgresweekly.com http://www.postgresweekly.com
- hackerboos 13y agoUsing Sublime as your editor for Postgres I had to add this to my ~/.zshrc: export EDITOR='subl -w'
- Choronzon 13y agoAs far as mac installs are concerned while i am fond of OSX for day to day usage you are way better putting your postgres install in a linux VM,it will reflect production better and be far easier to install.