Recently, I've had to move a postgresql database onto a separate server and split it out from the django application server.
On doing so, we saw intermittent «OperationalError: could not connect to server: Connection timed out».
This was quite obvious that the «connect_timeout» had to be increased to resolve the issue due to the latency introduced by the network. However, psycopg2 database adapter was being used which did not support the «connect_timeout» option to be passed via django.
We were able to work around the issue setting the environmental variable «PGCONNECT_TIMEOUT» so libpq would pick up the connection parameter.
While setting up munin to monitor postgresql, I was getting [DBD::Pg not found, and cannot do psql yet]"" when running `munin-node-configure --suggest | grep postgres`.
I confirmed that the rpm package «perl-DBI-1.52-2.el5» was indeed installed.
However, when I ran a test against the module, it failed with:
# perl -MDBD::Pg -e 1<br />Can't load '/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/Pg/Pg.so' for module DBD::Pg: libpq.so.4: cannot open shared object file: No such file or directory at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/DynaLoader.pm line 230.<br /> at -e line 0<br />Compilation failed in require.<br />BEGIN failed--compilation aborted.
On checking the library, it returned with «libpq.so.4 => not found»:
RPM of new version of are available in remi repository for Fedora 10 to 14.
The official site also provides RPM for Fedora 12.
To work, you need RPM Oracle Instant Client.
Pour l'installer, comme toujours :
yum --enablerepo=remi install toraThis tool can be used to manage your Oracle, PostgreSQL and MySQL databases. Despite this software is GPLv2, it can't be included in the official repository because of its link with... tora-2.1.3
RPM of new version of are available in remi repository for Fedora ≥ 9.
The official site also provides RPM for Fedora 12.
To work, you need RPM Oracle Instant Client.
Pour l'installer, comme toujours :
yum --enablerepo=remi install toraThis tool can be used to manage your Oracle, PostgreSQL and MySQL databases. Despite this software is GPLv2, it can't be included in the official repository because of its link with... tora-2.1.2
So, I tend to do a lot of lower-level stuff on OS-X such as compiling my own for development and testing purposes. One of the things that tends to interrupt the process of actually trying to run postgres is that it cannot change to the postgres user and it cannot run it as root.
In order to accomplish this you could make a user with your System Preferences which I have done in the past, the problem is then every time you log into your computer you’ll see this postgres user for no reason. Ugh, I hate that. So to work around this you just have to run the following commands in your OS-X terminal to add a group and user for postgres, with the user “home” being the default compilation target directory for PostgreSQL (/usr/local/pgsql)
This is confirmed to work on every version of Leopard and Snow Leopard.
Чтобы в PostgreSQL предоставить readonly доступ ко всем созданным к текущему моменту таблицам определенной БД (но за исключением системных таблиц), можно воспользоваться командой:
psql -U postgres -qAt -c "select 'grant select on ' || tablename || ' to username;' from pg_tables where schemaname = 'public'" db_name | psql -U postgres db_name
Где вместо «grant select on» можно указать список доступов, к примеру "grant select, update, insert, delete on ".
Имя супер-пользователя: postgres, название БД, к таблицам которой предоставляется доступ: db_name, название пользователя, которому предоставляется ограниченный доступ: username.
Делаю очередной проект на Ruby on Rails. Как обычно, в миграциях понадобились foreign keys на уровне БД. Окинул взглядом все плагины, которые смог найти в google и на github.com. Ни один из них не умеет делать FK, используя и .
Поэтому сел и написал свой плагин: .
Установка:
Rails::Initializer.run do |config|
...
config.gem "active_record_foreign_keys", :source => "http://gemcutter.org"
...
end
$ rake gems:install
Использование:
def self.up
# create reference table
create_table :users do |t|
end
# create referencing table
create_table :a_examples do |t|
t.references :user, :foreign_key => true
end
# or
create_table :b_examples do |t|
t.references :user, :foreign_key => { n_update => :cascade, n_delete => :restrict }
end
# or
create_table :c_examples do |t|
end
add_foreign_key :c_examples, :user_id, :users, :id, n_update => :no_action, n_delete => :set_null
# or change existing table
change_table :d_examples do |t|
t.references :user, :foreign_key => true
end
end
def self.down
# remove constraint
remove_foreign_key :examples, :user_id, :users, :id
end
Плагин тестировался только под PostgreSQL, но по идее должен работать и под MySQL, и под Sqlite.
В этой заметке описано, как установить memcached на ту же машину, где уже запущен pgbouncer (из репозитория pgdg). Сложность в том, что pgbouncer использует более новую версию libevent, чем memcached, в результате чего memcached при установке выдает «transaction failed».
Один из наиболее красивых выходов из ситуации — пересборка SRPM с новой библиотекой libevent, а заодно и новой версией memcached.
В случае, если репозиторий pgdg еще не установлен, его можно инсталировать следующей командой (версию можно выбрать на странице )
Я активно начал пробовать завести rails-приложения на ruby 1.9.1. В целом, все неплохо работает, но мелкие косяки бывают. Например, в .
Для работы с пришлось доработать гем postgres. Теперь гем компилируется как под ruby 1.8, так и под ruby 1.9. Кроме того, всем строковым данным, которые возвращает БД, навешивается кодировка из Encoding.external_encoding. Поставить доработанный гем можно командой:
Но я хотел о другом написать. Об ошибке несовместимости кодировок ASCII-8BIT и UTF-8: ActionView::TemplateError (incompatible character encodings: ASCII-8BIT and UTF-8). Такая ошибка появляется при запуске Rails на ruby 1.9.1. В edge-версии rails ошибка все еще не исправлена. Для исправления нужно закинуть в config/initializers/.