Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Keep the max conn limitaion after restoring

  Fix the bug that after restoring, the max conn limitation is set to -1

Change-Id: I7067d87356d9a6820f02b1fac12a0a99474b08b2
  • Loading branch information...
commit ea94587aa2945cda5118af065d94a36e972c1d62 1 parent ac31866
Frank Lu authored
View
9 postgresql/lib/postgresql_service/node.rb
@@ -93,6 +93,9 @@ def migrate_instance(provisionedservice)
manage_temp_privilege(provisionedservice.name)
# In earlier releases, users should not have create privilege to create schmea in databases.
manage_create_privilege(provisionedservice.name)
+ # Fix the bug: when restoring database, the max connection limit is set to -1
+ # https://www.pivotaltracker.com/story/show/34260725
+ manage_maxconnlimit(provisionedservice.name)
end
def get_expected_children(name)
@@ -219,6 +222,12 @@ def manage_create_privilege(name)
connection.close if connection
end
+ def manage_maxconnlimit(name)
+ @connection.query("update pg_database set datconnlimit=#{@max_db_conns} where datname='#{name}' and datconnlimit=-1")
+ rescue => x
+ @logger.warn("Exception while managing maxconnlimit on database #{name}: #{x}")
+ end
+
def announcement
@capacity_lock.synchronize do
{ :available_capacity => @capacity,
View
2  postgresql/lib/postgresql_service/util.rb
@@ -334,7 +334,7 @@ def drop_db(conn, db)
# Create database
def create_db(conn, db, db_info)
return unless conn
- if db_info["datconnlimit"].nil?
+ if db_info["datconnlimit"]
conn.query("create database #{db} with connection limit = #{db_info["datconnlimit"]}")
else
conn.query("create database #{db}")
View
20 postgresql/spec/postgresql_node_spec.rb
@@ -72,6 +72,7 @@ class PostgresqlError
tmp_db = @node.provision(@default_plan)
@test_dbs[tmp_db] = []
conn = connect_to_postgresql(tmp_db)
+ old_db_info = @node.get_db_info(conn, tmp_db["name"])
conn.query("create table test1(id int)")
conn.query("insert into test1 values(1)")
conn.query("create schema test_schema")
@@ -91,6 +92,8 @@ class PostgresqlError
conn.query("create table test_schema.test2(id int)")
@node.restore(tmp_db["name"], "/tmp").should == true
conn = connect_to_postgresql(tmp_db)
+ new_db_info = @node.get_db_info(conn, tmp_db["name"])
+ new_db_info["datconnlimit"].should == old_db_info["datconnlimit"]
res = conn.query("select tablename from pg_catalog.pg_tables where schemaname = 'public';")
res.count.should == 1
res[0]["tablename"].should == "test1"
@@ -787,6 +790,23 @@ class PostgresqlError
end
end
+ it "should be able to migrate(max_conns_limit) legacy instances" do
+ EM.run do
+ ori_db_info = @node.get_db_info(@node.connection, @db['name'])
+ ori_limit = ori_db_info['datconnlimit']
+ ori_limit.should_not == '-1'
+ @node.connection.query("update pg_database set datconnlimit=-1 where datname = '#{@db['name']}'")
+ @node.get_db_info(@node.connection, @db['name'])['datconnlimit'].should == '-1'
+ node = VCAP::Services::Postgresql::Node.new(@opts)
+ sleep(1)
+ EM.add_timer(0.1) {
+ @node.get_db_info(@node.connection, @db['name'])['datconnlimit'].should == ori_limit
+ node.get_db_info(node.connection, @db['name'])['datconnlimit'].should == ori_limit
+ EM.stop
+ }
+ end
+ end
+
it "should be able to migrate(grant create privilege) legacy instances" do
EM.run do
parent = @db['user']

0 comments on commit ea94587

Please sign in to comment.
Something went wrong with that request. Please try again.