python - 使用 Python 将表加载到 AWS RDS Postgres 需要很长时间

标签 python python-3.x pandas

我正在从 url 读取数据并将其加载到 AWS RDS Postgres。我正在使用免费套餐。数据大约有 150 万条记录,当我将其加载到本地 postgres 时,只需要大约 <10 分钟,但加载到 AWS Postgres 时,仅一个查询就需要永远(超过 15 小时)。如何提高性能或加快代码速度,以下是我正在使用的,请建议我一些好方法:

import pandas as pd
from sqlalchemy import create_engine
import zipfile
import os
from urllib.request import urlopen 
import urllib.request
import io
from io import BytesIO, StringIO



 pg_engine=create_engine('postgresql://user:password@host.amazonaws.com:5432/database')

 zf1 = zipfile.ZipFile(BytesIO(urllib.request.urlopen('http://wireless.fcc.gov/uls/data/complete/l_market.zip').read()))


df6_mk = pd.read_csv(zf1.open('MC.dat'),header=None,delimiter='|', index_col=0, names=['record_type', 'unique_system_identifier', 'uls_file_number','ebf_number','call_sign',
                        'undefined_partitioned_area_id','partition_sequence_number','partition_lat_degrees','partition_lat_minutes',
                        'partition_lat_seconds','partition_lat_direction','partition_long_degrees','partition_long_minutes','partition_long_seconds',
                        'partition_long_direction','undefined_partitioned_area'])

df6_mk.to_sql('mc_mk',pg_engine,if_exists='replace')

最佳答案

我相信免费套餐 RDS 选项的 R/W 容量限制为 5/秒,这会限制您的速度。

关于python - 使用 Python 将表加载到 AWS RDS Postgres 需要很长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55565160/

相关文章:

python - 如何使用 python 在邮件正文中发送 html 内容?

python - Bisect/Insort 的列表和双端队列的时间复杂度是否不同?

python - Seaborn.countplot : order categories by count

python - 如何删除 'NoneType' 的字典项?

python - pandas 当前行 * 上一行 + 上一行

python - Pandas - 按 'type' 选择行(不是 dtype)

python - 保存/加载 sympy lambdifed 表达式

带有mysql连接的python3 nameko RPC服务器

python-3.x - 在 python 中加载 FLAC 文件与 scipy 或 librosa 相同

python - 用于忠诚度计算的线路之间的时间增量