RDS for PostgreSQL 如何查看和确认内存规格?
一般两种方式:(1)show shared_buffer; 结果乘以4即总内存,我们一般配置shared_buffer是规格内存的1/4。(2)使用apenapi,https://help.aliyun.com/document_detail/rds/OpenAPI-manual/RDS-OpenAPI-InstanceManagement/DescribeDBInstanceAttribute.html?spm=5176.docrds/OpenAPI-manual/RDS-OpenAPI-ParameterManagement/ModifyeParameter.6.149.nIxWgG
openapi程序:!/usr/bin/pythoncoding:utf-8try: import httplibexcept ImportError:import http.client as httplibimport sysimport urllibimport urllib2import timeimport jsonimport itertoolsimport mimetypesimport base64import hmacimport uuidfrom hashlib import sha1
class AliyunMonitor:
def __init__(self,url):
self.access_id = 'your_accesid'
self.access_secret = 'your_secret'
self.url = url
签名
def sign(self,accessKeySecret, parameters):
sortedParameters = sorted(parameters.items(), key=lambda parameters: parameters[0])
canonicalizedQueryString = ''
for (k,v) in sortedParameters:
canonicalizedQueryString += '&' + self.percent_encode(k) + '=' + self.percent_encode(v)
stringToSign = 'GET&%2F&' + self.percent_encode(canonicalizedQueryString[1:]) #使用get请求方法
h = hmac.new(accessKeySecret + '&', stringToSign, sha1)
signature = base64.encodestring(h.digest()).strip()
return signature
def percent_encode(self,encodeStr):
encodeStr = str(encodeStr)
res = urllib.quote(encodeStr.decode(sys.stdin.encoding).encode('utf8'), '')
res = res.replace('+', '%20')
res = res.replace('*', '%2A')
res = res.replace('%7E', '~')
return res
def make_url(self,params):
timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
parameters = {
'Format' : 'JSON',
'Version' : '2014-08-15',
'AccessKeyId' : self.access_id,
'SignatureVersion' : '1.0',
'SignatureMethod' : 'HMAC-SHA1',
'SignatureNonce' : str(uuid.uuid1()),
'TimeStamp' : timestamp,
}
for key in params.keys():
parameters[key] = params[key]
signature = self.sign(self.access_secret,parameters)
parameters['Signature'] = signature
url = self.url + '/?' + urllib.urlencode(parameters)
return url
def do_request(self,params):
url = self.make_url(params)
print(url)
request = urllib2.Request(url)
try:
conn = urllib2.urlopen(request)
response = conn.read()
except urllib2.HTTPError, e:
print(e.read().strip())
raise SystemExit(e)
try:
obj = json.loads(response)
except ValueError, e:
raise SystemExit(e)
print obj
if name == '__main__':T = AliyunMonitor('https://rds.aliyuncs.com')T.do_request({'Action':'DescribeDBInstanceAttribute','DBInstanceId':'your_instance_name'})
赞1
踩1